IEnumerator SpawnTestEnemies() { var prefab = enemyList.GetEnemy(0); var boss = enemyList.GetEnemy(1); var spider = enemyList.GetEnemy(2); currentWave++; WaveChanged(currentWave, currentWave); int waveEnemyCount = (int)(5 * Mathf.Sqrt(Mathf.Pow(currentWave, 3))); float spawnDelay = Mathf.Max(5f / currentWave, 0.05f); Queue <WaveCommand> commands = new Queue <WaveCommand>(); yield return(new WaitForSeconds(6f)); switch (currentWave) { case 7: for (int i = 0; i < (waveEnemyCount / 3); i++) { commands.Enqueue(new SpawnPrefab(spider, enemyHolder, waypoints[0], waypoints)); spawnDelay = 0.25f; } break; case 10: commands.Enqueue(new SpawnPrefab(boss, enemyHolder, waypoints[0], waypoints)); break; default: for (int i = 0; i < waveEnemyCount; i++) { commands.Enqueue(new SpawnPrefab(prefab, enemyHolder, waypoints[0], waypoints)); } break; } while (commands.Count > 0) { commands.Dequeue().Execute(); yield return(new WaitForSeconds(spawnDelay)); } yield return(new WaitForSeconds(1f)); AwaitingNextWave = true; }