// spawns the enemies private void spawnEnemies() { // stops if all enemies spawned for this level if (currentlevel.maxEnemies > currentlevel.spawnedEnemies) { // blocking function if (enemySpawnBlock) { enemySpawnBlock = false; bool spawned = false; int counter = 0; while (!spawned) { // spawn enemy and deduct the enemy counter to switch the level int spawnspot = Random.Range(0, spawnSpots.Count - 1); EnemySpawnArea espArea = spawnSpots[spawnspot].GetComponentInChildren <EnemySpawnArea>(); if (!espArea.busy) { spawnEnemy(spawnSpots[spawnspot]); spawned = true; currentlevel.spawnedEnemies++; // if all enemies dead in this level, move on to next one // if (currentlevel.enemies-- == 0) // { // initLevel(); // } } // exits from a loop in case all spawn places busy if (counter++ > 6) { break; } } StartCoroutine(spawnWait(currentlevel.delay)); } } }
private void Awake() { EnemySpawnArea = FindObjectOfType <EnemySpawnArea>(); KittyBase = FindObjectOfType <KittyBase>(); }