public void StartWave(int waveIndex) { GameManager.GameState.CurrentWaveIndex = waveIndex; GameManager.GameState.NumEnemiesRemaining = waveData.numEnemies; // Create Wasps for the next wave for (int i = 0; i < waveData.numEnemies; i++) { Wasp wasp = _waspObjectPool.GetObjectFromPool(); wasp.health.onDeath += HandleEnemyDeath; wasp.transform.position = GetRandomSpawnPoint(); _wasps.Add(wasp); } onEnemyCountChanged?.Invoke(waveData.numEnemies); onWaveStarted?.Invoke(GameManager.GameState.CurrentWaveIndex); }
private void HandleEnemyDeath(GameObject enemy) { Wasp wasp = enemy.GetComponent <Wasp>(); wasp.health.onDeath -= HandleEnemyDeath; _waspObjectPool.ReturnObjectToPool(wasp); _wasps.Remove(wasp); GameManager.GameState.NumEnemiesRemaining -= 1; onEnemyCountChanged?.Invoke(GameManager.GameState.NumEnemiesRemaining); // Wave Ends If No Enemies! if (GameManager.GameState.NumEnemiesRemaining <= 0) { StartWave(GameManager.GameState.CurrentWaveIndex + 1); } }
/******* Monobehavior Methods *******/ public void Awake() { _wasp = GetComponent <Wasp>(); _aiState = new WaspAIState(); StartAI(); }