private IEnumerator SpawnEnemiesDeffered(AlienStageWaveSettings alienStageSettings, Action <AlienEnemy> onAlienCreatedAction, float spawnStartDelay) { int firstRowIndex = FormationGrid.CurrentRowIndex; FormationGrid.ReserveRows(alienStageSettings.FormationSettings.RowsCount); yield return(new WaitForSeconds(spawnStartDelay)); Vector3 spawnPosition = GetSpawnPosition(); for (int i = 0; i < alienStageSettings.AlienCount; i++) { Vector3 formationPosition = FormationGrid.EstimatePosition(i, firstRowIndex, alienStageSettings.FormationSettings.RowsCount); Vector3 currentSpawnPosition = ShouldInverseSpawnPosition(i) == true?spawnPosition.InverseX() : spawnPosition; AlienEnemy newAlien = CreateAlienEnemy(alienStageSettings.AlienEnemy, currentSpawnPosition); newAlien.SetFormationPosition(formationPosition); newAlien.SetAlienState(AlienEnemy.AlienStates.Appear); onAlienCreatedAction(newAlien); if (i % 2 != 0) { yield return(new WaitForSeconds(alienStageSettings.AlienSpawnDelay)); } } }
public void SpawnAlienEnemies(AlienStageWaveSettings alienStageSettings, Action <AlienEnemy> onAlienCreatedAction, float spawnStartDelay) { SpawnCoroutines.Add(StartCoroutine(SpawnEnemiesDeffered(alienStageSettings, onAlienCreatedAction, spawnStartDelay))); }