Unity3D 2018.2.4 C#在这个 spawner 代码中,它一直在实例化。我如何阻止生成从实例化直到所有生成的敌人都被摧毁。我正在检查if (destroyedEnemyCounter == enemyStartAmount)因为我正在计算所有被摧毁的敌人以及波生成器乘以敌人开始数量的多少但是即使我将波转发放在 if 语句中,代码也会继续实例化。在该波/轮的计数被破坏并能够移动到下一个波/轮之前,我将如何添加阻止生成器实例化的限制?这是我到目前为止的代码private int enemyStartAmount = 2;private int multiply = 2;private float startWait = 30.0f;private float spawnWait = 2.0f;private float waveWait = 28.0f;// Startprivate void OnEnable(){ startCountDownTimer = startWait; waveCurrentCount = 1; StartCoroutine(SpawnWaves());}// Updateprivate void FixedUpdate(){ // For Text: StartTimer if (isStartTimerFinished == false) { startCountDownTimer -= Time.deltaTime; } // For Text: When StartTimer isFinished if (isStartTimerFinished == false && startCountDownTimer <= 0f) { isStartTimerFinished = true; } // For Text: When startTimer ends and Spawner Starts if (isStartTimerFinished == true) { // Game Timer stopWatchTimer += Time.deltaTime; }}
2 回答
慕的地10843
TA贡献1785条经验 获得超8个赞
代替
if (destroyedEnemyCounter == enemyStartAmount)
和
yield return new WaitUntil(() => destroyedEnemyCounter == enemyStartAmount);
德玛西亚99
TA贡献1770条经验 获得超3个赞
检查后
if (destroyedEnemyCounter == enemyStartAmount)
循环将再次开始,再次生成enemyStartAmount。
您可以做的是在生成逻辑周围添加一个条件,例如bool readyForNextWave将您设置为trueinsideif (destroyedEnemyCounter == enemyStartAmount)
if(readyForNextWave)
{
readyForNextWave = false;
for (int i = 0; i < enemyStartAmount; i++)
{
// Each Wave is a different way
// ...
yield return new WaitForSeconds(spawnWait);
}
}
// ...
if (destroyedEnemyCounter == enemyStartAmount)
{
readyForNextWave = true;
Debug.Log("Next Wave Incoming");
// ...
}
- 2 回答
- 0 关注
- 392 浏览
添加回答
举报
0/150
提交
取消