/// <summary> /// Responsible for spawning enemies and waits until all enemies die before ending /// </summary> /// <returns></returns> private IEnumerator RoundPlay() { print("Round Play | " + _currentPhase); var numberOfEnemies = Wave.GetEnemiesForRound(_wave); // Array of Enemy_Abstracts to store the spawned enemies Enemy_Abstract[] enemies = new Enemy_Abstract[numberOfEnemies]; // Counter to track enemy count int counter = 0; while (counter < numberOfEnemies || !Wave.CheckEnemies(enemies)) { if (counter < numberOfEnemies) { // Random int which will be used to spawn enemies at a random spawner int rand = UnityEngine.Random.Range(0, _spawnLocations.Length); // Spawn a basic enemy at a random spawner enemies[counter] = Spawn(_spawnLocations[rand], "BasicEnemy"); yield return(new WaitForSecondsRealtime(Wave.SpawnWaitTime)); counter++; // Continue to the next iteration of the loop continue; } // Need this to stop infinite loop yield return(new WaitForSeconds(0.1f)); } _currentPhase = Phase.Wait; yield return(null); }