作者smailzhu (嗯嗯)
看板GameDesign
标题[请益] Unity StartCoroutine for loop
时间Mon Jan 2 19:30:43 2017
各位前辈,小弟我在练习开发android上的游戏
我在电脑上执行
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex) ;
可以成功的重新开始这个scene
但是当我输出成APK到手机上执行时
敌人就没有办法顺利生成
我敌人生成的方式是在start()内呼叫 StartCoroutine (SpawnWaves ());
IEnumerator SpawnWaves (){
yield return new WaitForSeconds (startWait);
while(true){
for (int i = 0; i < hazardCount; ++i){
Vector3 spawnPosition =
new Vector3 (Random.Range (xMin, xMax), yMax, 0);
//我有测试在这边将xMin,xMax,yMax,hazard,hazardCount,i,Time.time显示在萤幕上
//在还没有重新执行时i都顺利增加,Time.time也会跑,可是当我重新开始时i跟时间
//就只会卡在一个值了
Instantiate (hazard, spawnPosition, transform.rotation);
yield return new WaitForSeconds (spawnWait);
}
yield return new WaitForSeconds (waveWait);
if (gameOver) {
restartText.text = "Double click to Restart";
restart = true;
break;
}
}
}
想请教各位前辈可以帮我提点一下吗,谢谢
--
███◣ ██◣ ███◣ ██◣ █◣ ███◣ █◣◥◣ █◣◥◣
████ ███◣ ████ ◥██ ██ ◥███ ██◣█ █
█◣
█
██▆▆ █▉▉▉ ██▆█ ◣ █ ███◣ ◣◢█◤ ████ █
██
█
◥▆▆█ ◥▉◥▉ ◥█ █ ◥██ ◥███ ◥███ ◥█◣█ ◥
██◤ ★
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▃▃▃▃▂▂▂▁▁
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.34.64.242
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/GameDesign/M.1483356647.A.4D3.html
1F:→ gyd: 请定义 i跟time卡在一个值, 下次请试着将状况讲清楚 01/03 00:38
2F:→ gyd: 没有完整code的情况只能帮你抓逻辑错误而已 01/03 00:39
3F:→ smailzhu: 我觉得time卡的那个值应该是进去for回圈的那个时间点, 01/03 04:41
4F:→ smailzhu: 至於i的话是卡再0不会增加 01/03 04:41
5F:→ smailzhu: 谢谢提点,我晚点会Po程式码 01/03 04:42
6F:→ smailzhu: 我觉得最困扰的是,电脑上可以顺利重来,可是手机无法 01/03 09:23