private IEnumerator SpawnAllBEATzInWave(WaveConfiguration waveConfig) { // For each number of BEATz that we will spawn in the scene, we will increment the BEAT count by 1. for (int BEATCount = 0; BEATCount < waveConfig.GetSpawnNumber(); BEATCount++) { // Local Variables // 1.) The BEAT that we will be spawning var BEAT = waveConfig.GetBEATPrefab(); // 2.) The BEAT position on spawn var BEATPosition = waveConfig.GetWaypoints()[0].transform.position; // 3.) Spawn BEAT var newBEAT = Instantiate(BEAT, BEATPosition, Quaternion.identity); // 4.) The starting time of a spawn pattern. int startingSpawnDuration = 0; // 5.) The duration time of spawning BEATz float endingSpawnDuration = waveConfig.GetSpawnDuration(); SpawnBEATz(waveConfig, BEAT, newBEAT); // Wait before spawning another BEAT. yield return(new WaitForSeconds(waveConfig.GetSpawnRate())); BEATCount = SpawnAnotherBEAT(waveConfig, BEATCount, startingSpawnDuration, endingSpawnDuration); // If delay is ON, then wait a second. if (waveConfig.GetDelay() && endingSpawnDuration == startingSpawnDuration) { yield return(new WaitForSeconds(waveConfig.GetDelayInterval())); } } }