楼主:
gyd (阿龙哥)
2017-01-03 01:00:08这是我重现的code, 在pc上执行起来没问题
( 推荐一个plugin http://u3d.as/5E8 )
从你的描述上看, 你应该有做所谓的暂停的功能
请检查你是否有在特定条件下把Time.timeScale设为0 (或小值, 如0.05f)
并且请在切Scene前或切Scene后将其重设为1
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class GameControl : MonoBehaviour
{
float startWait = 0.5f;
float spawnWait = 0.5f;
float waveWait = 0.5f;
int hazardCount = 5;
float xMin = -10f;
float xMax = 10f;
float yMax = 10f;
bool gameOver = true;
int waveCount = 1;
void 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);
Debug.LogFormat( "{0} trying to create enemy: {1} at {2}",
waveCount, i, spawnPosition );
yield return new WaitForSeconds (spawnWait);
}
waveCount++;
yield return new WaitForSeconds (waveWait);
if( waveCount > 3 )
{
Debug.Log( "Restart" );
Reload();
break;
}
}
}
void Reload()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
※ 引述《smailzhu (嗯嗯)》之铭言:
: 各位前辈,小弟我在练习开发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;
: }
: }
: }
: 想请教各位前辈可以帮我提点一下吗,谢谢
楼主:
gyd (阿龙哥)
2017-01-03 01:01:00补充一下, 在此前题下, 会卡住不是因为Coroutine, 是因为WaitForSeconds