private EnemyWave.SubWave PrepareSubWave() { if (currentSubWaveIndex < 0) { currentSubWaveIndex = 0; } // `subWave` should never be `null`, as `currentSubWaveIndex` should always reflect the current, valid sub-wave EnemyWave.SubWave subWave = waves[currentWaveIndex].GetSubWave(currentSubWaveIndex); if (subWave.IsPause) { // If the current sub-wave is a pause sub-wave, that means it's already over, // so return the next one (if it exists) return(GoToNextSubWave(currentWaveIndex)); } if (currentSubWaveEnemyCounter < subWave.number) { // Can continue with sub-wave, so return it return(subWave); } else { // Sub-wave is over, so return the next one (if it exists) return(GoToNextSubWave(currentWaveIndex)); } }
private EnemyWave.SubWave GoToNextSubWave(int waveIndex) { // Check next sub-wave: EnemyWave.SubWave subWave = waves[waveIndex].GetSubWave(currentSubWaveIndex + 1); if (subWave != null) { // Update sub-wave index and reset enemy counter currentSubWaveIndex++; currentSubWaveEnemyCounter = 0; } return(subWave); }
private void SpawnNextEnemy() { EnemyWave.SubWave subWave = PrepareSubWave(); if (subWave == null) { // Reached the end of the sub-wave(s), and therefore also the current wave hasWaveEnded = true; return; } if (subWave.IsPause) { timeUntilNextSpawn = subWave.pauseDuration; return; } enemyManager.SpawnEnemy(subWave.enemyType); currentSubWaveEnemyCounter++; }