public IEnumerator Init(Node startNode, int numberOfEnemies) { UnitDatabase unitDatabase = FindObjectOfType <UnitDatabase>(); isSpawning = true; while (numberOfEnemies != 0) { if (enemyViewGO != null && startNode.position != null) { GameObject instance = Instantiate(enemyViewGO, startNode.position, Quaternion.identity, this.transform); Unit unit = new Unit(startNode); EnemyMovement enemyMovement = InitComponents(instance, unit); unitDatabase.AddNewEnemy(enemyMovement, startNode, unit); numberOfEnemies--; } yield return(new WaitForSeconds(secsBetweenSpawnTime)); } isSpawning = false; }