示例#1
0
    public IEnumerator SpawnWeightedRandomEnemy(WaveManagerScriptableObject.Wave wave)
    {
        int  activeEnemyCount = 0;
        bool controlVar       = true;

        while (controlVar)
        {
            if (activeEnemyCount < wave.waveEnemyCount)
            {
                Vector3 position = spawnPoints[Random.Range(0, spawnPoints.Count)].transform.position;

                Instantiate(wave.EnemiesList[GetRandomWeightedIndex(wave.enemiesWeightOrNumber)],
                            new Vector3(position.x, position.y, 0.0f),
                            Quaternion.identity);

                ++_gameManager.activeEnemies;
                ++activeEnemyCount;
            }
            else if (activeEnemyCount == wave.waveEnemyCount)
            {
                controlVar = false;
            }

            yield return(new WaitForSeconds(wave.enemySpawnInterval));
        }
    }
示例#2
0
    public IEnumerator SpawnRandomEnemy(WaveManagerScriptableObject.Wave wave, bool isEndless = false)
    {
        int  activeEnemyCount = 0;
        bool controlVar       = true;

        if (!isEndless)
        {
            while (controlVar)
            {
                if (activeEnemyCount < wave.waveEnemyCount)
                {
                    int     t        = Random.Range(0, spawnPoints.Count);
                    Vector3 position = new Vector3(spawnPoints[t].transform.position.x, spawnPoints[t].transform.position.y, 0);

                    Instantiate(wave.EnemiesList[Random.Range(0, wave.EnemiesList.Count)],
                                new Vector3(position.x, position.y, 0.0f),
                                Quaternion.identity);

                    ++_gameManager.activeEnemies;
                    ++activeEnemyCount;
                }
                else if (activeEnemyCount == wave.waveEnemyCount)
                {
                    controlVar = false;
                }

                yield return(new WaitForSeconds(wave.enemySpawnInterval));
            }
        }
        else
        {
            while (controlVar)
            {
                int sizeOfWave = Random.Range(0, 100);
                if (activeEnemyCount < sizeOfWave)
                {
                    Vector3 position = spawnPoints[Random.Range(0, spawnPoints.Count)].transform.position;
                    Instantiate(wave.EnemiesList[Random.Range(0, wave.EnemiesList.Count)], new Vector3(position.x, position.y, 0.0f),
                                Quaternion.identity);
                    ++activeEnemyCount;
                }
                else if (activeEnemyCount == sizeOfWave)
                {
                    controlVar = false;
                }

                yield return(new WaitForSeconds(2f));
            }
        }
    }
示例#3
0
    public IEnumerator SpawnSpecificEnemies(WaveManagerScriptableObject.Wave wave)
    {
        int  activeEnemyCount = 0;
        bool controlVar       = true;

        for (int i = 0; i < wave.EnemiesList.Count; i++)
        {
            for (int j = 0; j < wave.enemiesWeightOrNumber[i]; j++)
            {
                int     t        = Random.Range(0, spawnPoints.Count);
                Vector3 position = new Vector3(spawnPoints[t].transform.position.x, spawnPoints[t].transform.position.y, 0);

                Instantiate(wave.EnemiesList[i],
                            new Vector3(position.x, position.y, 0.0f),
                            Quaternion.identity);

                _gameManager.activeEnemies++;
                ++activeEnemyCount;

                yield return(new WaitForSeconds(wave.enemySpawnInterval));
            }
        }
    }