IEnumerator SpawnEnemyUnit(PH_WaveConfig waveConfig) { string WaveTag = waveConfig.name.Replace(" ", "");//create the tag by removing the spaces int OnScreenEnemyCount; int currentUnit = waveConfig.GetEnemyUnitCount(); do // add at leat one enemy each cycle { var newEnemy = Instantiate(waveConfig.GetEnemyPrefab(), waveConfig.GetWayPoints()[0].transform.position, Quaternion.identity); //creates the new object froma prefab, initial position is the first waypoint, default rotation newEnemy.GetComponent <PH_EnemyPath>().SetWaveConfig(waveConfig); //gives the information from the enemy template to the enemy path script newEnemy.tag = WaveTag; //assign the tag to the enemy currentUnit--; OnScreenEnemyCount = GameObject.FindGameObjectsWithTag(WaveTag).Length; //returns the length of the list of all gameObjects that wear this tag yield return(new WaitForSeconds(waveConfig.GetSpawnRate())); //wait the delay before cllaing the next foe }while (OnScreenEnemyCount < waveConfig.GetEnemyUnitCount() && currentUnit > 0); }
public void SetWaveConfig(PH_WaveConfig waveConfig)//method to set the config file from another script { EnemySettings = waveConfig; }