//function call to spawn a subwave IEnumerator SpawnSubWave(Wave wave, int subWaveIdx) { SubWave subWave = wave.subWaveList[subWaveIdx]; TDSArea sArea = subWave.spawnArea != null ? subWave.spawnArea : spawnAreaList[0]; //use the default spawn area if nothing has been assigned for the subwave //wait for start delay yield return(new WaitForSeconds(subWave.startDelay)); if (subWave.unitPrefab != null) { for (int i = 0; i < subWave.count; i++) { //wait for the spawn cooldown if (i > 0) { yield return(new WaitForSeconds(subWave.interval)); } Quaternion rot = !randomRotation?sArea.GetRotation() : Quaternion.Euler(0, Random.Range(0, 360), 0); UnitAI unitInstance = SpawnUnit(subWave.unitPrefab.gameObject, sArea.GetPosition(), rot, subWave.unitPrefab.gameObject.name + "_" + spawnCount); unitInstance.SetWaveID(this, wave.waveID); //assign the unit with the waveID so they know they belong to a wave (unit with valid waveID will call UnitCleared() callback) wave.activeUnitCount += 1; } } //increase the subWaveSpawned counter wave.subWaveSpawned += 1; yield return(null); }
IEnumerator SpawnRoutine() { yield return(new WaitForSeconds(startDelay)); //keep on looping while (true) { Collectible newObj = SpawnItem(spawnArea.GetPosition()); if (newObj != null) { newObj.SetTriggerCallback(this.ItemTriggeredCallback); //set callback function for the collectible (which clear the item in existingItemList) existingItemList.Add(newObj); //add the new item to existingItemList } //wait for spawnCD before attempting next spawn yield return(new WaitForSeconds(spawnCD)); } }