Esempio n. 1
0
    //Spawns all enemies in the given waveConfig based on its parameters
    IEnumerator SpawnEnemiesInStruct(GameObject enemyPrefab, int numEnemies, WaveConfig waveConfig)
    {
        Debug.Log("Running structs");
        _spawning = true;
        _activeWaves++;
        if (_activeWaves > 1)
        {
            yield return(new WaitForSeconds(waveConfig.GetDelayBetweenSpawns() * _activeWaves * 2));
        }

        for (int numSpawned = 0; numSpawned < numEnemies; numSpawned++)
        {
            var enemy = Instantiate(enemyPrefab,
                                    _spawnpoints[FindRandomSpawnpointIndex()].transform.position,
                                    Quaternion.identity);
            enemy.transform.parent = gameObject.transform;
            yield return(new WaitForSeconds(waveConfig.GetDelayBetweenSpawns() + Random.Range(-waveConfig.GetRandomSpawnOffset(),
                                                                                              waveConfig.GetRandomSpawnOffset())));
        }
        _activeWaves--;
        if (_activeWaves == 0)
        {
            _spawning = false;
            shopCounter++;
        }
    }