I have a spawner script that will yield return new WaitforSeconds a certain amount of time, then spit out an enemy.
public IEnumerator StartEnemyWave (int numberOfEnemies, float interval)
{
float temp = interval / uIController.levelProgressTotal;
uIController.actualProgressBarTotal += temp;
//spawns a certain amount of enemies inbetween a variable interval
for (int i = 0; i < numberOfEnemies; i++)
{
if (!levelController.gameOver)
{
int enemyIndex = levelController.currentSpawnData.enemySelection [levelController.currentWave].enemiesThisWave *;*
SpitOutEnemy (enemyIndex);
print ("spawning : " + levelController.currentSpawnData.enemySelection [levelController.currentWave].enemiesThisWave.Length);
print ("every " + levelController.currentSpawnData.timeBetweenEnemies [levelController.currentWave]);
yield return new WaitForSeconds (interval);
}
else
{
print (“stopping the spawner”);
yield return null;
}
- }*
My problem is in that I can’t seem to shut this coroutine down when I want to.
I tried making a cheat button which ends the level and brings you back to the level select screen. In that button press it has the function “StopAllCoroutines()”. But when I select a new level, sure enough the spawner is still firing off enemies having never been shut down.
What am I missing here? What would cause StopAllCoroutines to not find this and shut it down, even during a yield return new WaitForSeconds(); ?