// Use this for initialization IEnumerator Start() { while (true) { GameObject clone = Instantiate(enemies[Random.Range(0, enemies.Length)], transform.position, Quaternion.identity) as GameObject; DieOnHit dieOnHit = clone.GetComponent <DieOnHit> (); dieOnHit.SetGameController(gameController); yield return(new WaitForSeconds(Random.Range(1f, spawnRate))); } }
// Use this for initialization IEnumerator SpawnLoop() { while (true) { int randomPoolIndex = Random.Range(0, objectPools.Length); GameObject clone = objectPools[randomPoolIndex].GetObject(); clone.SetActive(true); int randomSpawnPointIndex = Random.Range(0, spawnPoints.Length); clone.transform.position = spawnPoints [randomSpawnPointIndex].position; DieOnHit dieOnHit = clone.GetComponent <DieOnHit> (); dieOnHit.SetGameController(gameController); yield return(new WaitForSeconds(Random.Range(1f, spawnRate))); } }
// запуск волны IEnumerator SpawnLoop() { // вернем нашей текстовой метке нормальный цвет MM.scoreValueDisplay.GetComponent <Text>().color = originalScoreTextColor; gC.setIsGame(true); while (true) { int randomIndex = -1; if (listNowWave.Count > 0) { randomIndex = UnityEngine.Random.Range(0, listNowWave.Count - 1); } else { print("listNowWave.Count = 0 indexWave++"); indexWave++; if (indexWave < newLevel.GetCountWaves()) { StopSpawning(); } else { print("END ALL WAVES ON LEVEL"); } yield break; } int indexPool = -1; switch (listNowWave [randomIndex]) { case LevelManager.EnemiesUnit.Peasant: // TODO: можно заменить напрямую на (int)Enum без свитча indexPool = 0; break; case LevelManager.EnemiesUnit.Melnik: indexPool = 1; break; default: break; } if (indexPool == -1) { print("indexPool == -1"); yield break; } listNowWave.RemoveAt(randomIndex); GameObject clone = objectPools[indexPool].GetObject(); clone.SetActive(true); int randomSpawnPointIndex = UnityEngine.Random.Range(0, spawnPoints.Length); clone.transform.position = spawnPoints [randomSpawnPointIndex].position; clone.transform.SetParent(enemies); DieOnHit dieOnHit = clone.GetComponent <DieOnHit> (); dieOnHit.SetGameController(gC); gC.AddEnemyToList(clone); yield return(new WaitForSeconds(UnityEngine.Random.Range(1f, spawnRate))); } }