private IEnumerator SpawnRoutine() { // Wait for a while before spawning the first enemy yield return(new WaitForSeconds(waitBeforeSpawning)); while (true) { if (enemyCount < maxConcurrentEnemyCount) { // Spawns an enemy EnemySpaceShip enemy = SpawnEnemyUnit(); // If an enemy was successfully spawned, // the enemy count is increased if (enemy != null) { enemyCount++; } else { Debug.LogError("Could not spawn an enemy."); yield break; } } yield return(new WaitForSeconds(spawnInterval)); } }
private EnemySpaceShip SpawnEnemyUnit() { GameObject spawnedEnemyObject = _enemySpawner.Spawn(); EnemySpaceShip enemyShip = spawnedEnemyObject.GetComponent <EnemySpaceShip>(); if (enemyShip != null) { enemyShip.SetMovementTargets(_enemyMovementTargets); } return(enemyShip); }
private EnemySpaceShip SpawnEnemyUnit() { EnemySpaceShip enemyShip = enemySpawner.Spawn(). GetComponent <EnemySpaceShip>(); if (enemyShip != null) { enemyShip.SetMovementTargets(enemyMovementTargets); } return(enemyShip); }
private IEnumerator SpawnRoutine() { yield return(new WaitForSeconds(_waitToSpawn)); while (_enemyCount < _maxEnemyOnField) { EnemySpaceShip enemy = SpawnEnemyUnit(); if (enemy != null) { _enemyCount++; } else { Debug.LogError("Could not spawn an enemy!"); yield break; } yield return(new WaitForSeconds(_spawnInterval)); } }
private IEnumerator SpawnEnemyRoutine() { // Wait for a while before spawning the first enemy. yield return(new WaitForSeconds(_waitToSpawn)); while (_enemyCount < _maxEnemyUnitsToSpawn) { EnemySpaceShip enemy = SpawnEnemyUnit(); if (enemy != null) { _enemyCount++; } else { Debug.LogError("Could not spawn an enemy!"); yield break; //Stops the execution of this coroutine. } yield return(new WaitForSeconds(_spawnInterval)); } }
private IEnumerator SpawnRoutine() { // Initial grace period: yield return(new WaitForSeconds(_waitToSpawn)); while (_enemyCount < _maxEnemyUnitsToSpawn) { EnemySpaceShip enemy = SpawnEnemyUnit(); if (enemy != null) { _enemyCount++; } else { Debug.LogError("Could not spawn enemy"); // Stop the execution yield break; } yield return(new WaitForSeconds(_spawnInterval)); } }