Beispiel #1
0
    private IEnumerator SpawnAllEnemiesInWave(WaveConfig waveConfig)
    {
        yield return(new WaitForSeconds(waveConfig.GetWaitBeforeStart()));

        for (int spawnCount = 1; spawnCount <= waveConfig.GetNumberOfSpawns(); spawnCount++)
        {
            if (waveConfig.isBoss == false)
            {
                GameObject newEnemy = Instantiate(waveConfig.GetEnemyPrefab(), waveConfig.GetWaypointList()[0].transform.position, waveConfig.GetEnemyPrefab().transform.rotation);
                newEnemy.GetComponent <EnemyPathing>().SetWaveConfig(waveConfig);
                if (spawnCount == waveConfig.GetNumberOfSpawns())
                {
                    Enemy newEnemyScript = newEnemy.GetComponent <Enemy>();

                    if (waveConfig.DifDropChance() == true)
                    {
                        newEnemyScript.SetDropChance(waveConfig.GetDropChance());
                    }

                    if (waveConfig.IsSectorEnd() == true)
                    {
                        newEnemyScript.SetLastInSector(true);
                        newEnemyScript.SetNextSector(waveConfig.GetNextSector());
                    }
                }
            }
            else if (waveConfig.isBoss == true)
            {
                redBoss.SetActive(true);
            }


            yield return(new WaitForSeconds(waveConfig.GetSpawnInterval()));
        }
    }
Beispiel #2
0
    private IEnumerator SpawnWaveEnemies(WaveConfig theConfig)
    {
        for (int i = 0; i < theConfig.GetNumberOfSpawns(); i++)
        {
            var currentEnemy = Instantiate(theConfig.GetEnemyPrefab(),
                                           theConfig.GetPathWaypoints()[0].transform.position,
                                           Quaternion.identity);
            //this way we control wave settings in the waveconfigs (Assets/Waves/waveconfigs)
            //rather than variables in the scripts.
            currentEnemy.GetComponent <EnemyPathing>().SetWaveConfig(theConfig);

            yield return(new WaitForSeconds(theConfig.GetTimeBetweenSpawn()));
        }
    }