Example #1
0
        private void SpawnEnemyWave(LevelWaveConfig currentLevelWave, int i)
        {
            var currentEnemyWave = currentLevelWave.EnemyWaveConfigs[i];
            var enemyPathing     = Instantiate(enemyPathingObject).GetComponent <EnemyPathing>();

            enemyPathing.SetEnemyWaveConfig(currentEnemyWave);
            StartCoroutine(SpawnAllEnemiesInEnemyWave(currentEnemyWave, enemyPathing, currentLevelWave,
                                                      i == currentLevelWave.EnemyWaveConfigs.Count - 1));
        }
Example #2
0
 private IEnumerator SpawnLevelWave(LevelWaveConfig currentLevelWave)
 {
     currentLevelWave.WaveSpawning = true;
     ChangeMusic(currentLevelWave);
     for (var i = currentLevelWave.StartingEnemyWave; i < currentLevelWave.EnemyWaveConfigs.Count; i++)
     {
         SpawnEnemyWave(currentLevelWave, i);
         yield return(new WaitForSeconds(currentLevelWave.TimeBetweenEnemyWaveSpawns));
     }
 }
Example #3
0
        private void ChangeMusic(LevelWaveConfig currentLevelWave)
        {
            if (audioSource == null)
            {
                return;
            }
            var currentClip = audioSource.clip;
            var nextClip    = defaultClip;

            if (currentLevelWave.LevelWaveMusic != null)
            {
                nextClip = currentLevelWave.LevelWaveMusic;
            }

            if (currentClip == nextClip)
            {
                return;
            }
            audioSource.clip = nextClip;
            audioSource.Play();
        }
Example #4
0
        private IEnumerator SpawnAllEnemiesInEnemyWave(EnemyWaveConfig enemyWaveConfig, EnemyPathing enemyPathing,
                                                       LevelWaveConfig currentLevelWave, bool last)
        {
            yield return(new WaitForSeconds(enemyWaveConfig.SpawnDelay));

            do
            {
                for (var i = 0; i < enemyWaveConfig.NumberOfEnemies; i++)
                {
                    SpawnEnemy(enemyWaveConfig, enemyPathing);
                    yield return(new WaitForSeconds(Random.Range(enemyWaveConfig.MinTimeBetweenSpawns,
                                                                 enemyWaveConfig.MaxTimeBetweenSpawns)));
                }
            } while (enemyWaveConfig.ContinuousSpawning &&
                     (currentLevelWave.WaveSpawning || FindObjectsOfType <Enemy>().Length > 0));

            if (last)
            {
                currentLevelWave.WaveSpawning = false;
            }
        }