I'm trying to stop waves spawning upon player death but I cant seem to stop the coroutine. I don't really know how to attack this any more because adding if statements and breaks didn't work. How do I call StopCoroutine and have the routine stop? Would I need to introduce new methods and such?
void Start () {
gameOver = false;
StartCoroutine (SpawnWaves());
}
void Update()
{
if (gameOver)
{
StopCoroutine(SpawnWaves());
}
}
IEnumerator SpawnWaves()
{
yield return new WaitForSeconds(startWait);
while (true)
{
for (int i = 0; i < hazardCount; i++)
{
GameObject enemy = enemies[Random.Range(0, enemies.Length)];
Instantiate(enemy, spawnPosition1, spawnRotation1);
Instantiate(enemy, spawnPosition2, spawnRotation2);
Instantiate(enemy, spawnPosition3, spawnRotation3);
Instantiate(enemy, spawnPosition4, spawnRotation4);
Instantiate(enemy, spawnPosition5, spawnRotation5);
Instantiate(enemy, spawnPosition6, spawnRotation6);
yield return new WaitForSeconds(spawnWait);
}
yield return new WaitForSeconds(waveWait);
enemies[0].GetComponent<EnemyBehviour>().currentHealth *= enemyHealthMultiplier;
}
}
For example set gameOver = true
when currentHealth == 0
inside the while loop and set while(gameOver == false)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加