IEnumerator SpawnSubWave(SubWave subWave, Wave parentWave) { yield return(new WaitForSeconds(subWave.delay)); PathTD path = defaultPath; if (subWave.path != null) { path = subWave.path; } Vector3 pos = path.GetSpawnPoint().position; Quaternion rot = path.GetSpawnPoint().rotation; int spawnCount = 0; while (spawnCount < subWave.count) { GameObject obj = ObjectPoolManager.Spawn(subWave.unit, pos, rot); UnitCreep unit = obj.GetComponent <UnitCreep>(); if (subWave.overrideHP > 0) { unit.OverrideByHP(subWave.overrideHP); } else { unit.OverrideByWave(parentWave.waveID, developPerWave); } unit.Init(path, totalSpawnCount, parentWave.waveID); totalSpawnCount += 1; activeUnitCount += 1; parentWave.activeUnitCount += 1; spawnCount += 1; if (spawnCount == subWave.count) { break; } yield return(new WaitForSeconds(subWave.interval)); } parentWave.subWaveSpawnedCount += 1; if (parentWave.subWaveSpawnedCount == parentWave.subWaveList.Count) { parentWave.spawned = true; spawning = false; Debug.Log("wave " + (parentWave.waveID + 1) + " has done spawning"); yield return(new WaitForSeconds(0.5f)); if (currentWaveID <= waveList.Count - 2) { //for UI to show spawn button again if (spawnMode == _SpawnMode.Continous && allowSkip && onEnableSpawnE != null) { onEnableSpawnE(); } if (spawnMode == _SpawnMode.WaveCleared && allowSkip && onEnableSpawnE != null) { onEnableSpawnE(); } } } }