예제 #1
0
    public IEnumerator SpawnEnemy()
    {
        int w = 0;

        while (_spawnDone == false && w < _waves.Count)
        {
            WaveSystem wave           = _waves[w];
            int        enemiesToSpawn = 0;

            if (wave.bossWave == false)
            {
                enemiesStillAlive = wave.numberOfEnemiesToSpawn;
                enemiesToSpawn    = wave.numberOfEnemiesToSpawn;
            }
            else
            {
                _boss.SetActive(true);
                enemiesStillAlive = 1;
            }

            UIManager.Instance.UpdateWaveUIText(w + 1);
            int sheildedEnem = 0;
            _canDodge = wave.VerticaleEnemiesDodge;

            while (enemiesStillAlive != 0)
            {
                if (wave.bossWave == false)
                {
                    if (enemiesToSpawn > 0)
                    {
                        foreach (var e in _enemies)
                        {
                            if (e.activeInHierarchy == false && e != null)
                            {
                                Enemy en  = e.GetComponent <Enemy>();
                                int   can = Random.Range(0, 2);
                                if (en != null)
                                {
                                    if (sheildedEnem < wave.sheildedEnemies)
                                    {
                                        en.ActiveSheild(true);
                                        sheildedEnem++;
                                    }

                                    if (wave.canEnemiesZigzag == true)
                                    {
                                        if (can == 1)
                                        {
                                            en._activeZigZag = true;
                                        }
                                        else
                                        {
                                            en._activeZigZag = false;
                                        }
                                    }

                                    en.canFireFromBehind = wave.enemiesCanShootFromBehind;
                                    en.canShoot          = wave.enemiesCanShoot;
                                    en.ChooseRandomMouvementType();
                                    EnemyMouvementType(en);
                                }
                                e.SetActive(true);
                                enemiesToSpawn--;
                                break;
                            }
                        }
                        yield return(new WaitForSeconds(_enemySpawnTime));
                    }

                    if (enemiesStillAlive == -1)
                    {
                        enemiesStillAlive = 0; // bug fix
                    }
                }
                yield return(null);
            }
            UIManager.Instance.UpdateCountDownUI(wave.cooldownToStartNextWave);
            yield return(new WaitForSeconds(wave.cooldownToStartNextWave));

            w++;
        }

        if (_spawnDone == false)
        {
            UIManager.Instance.UpdateWaveUIText(-1);
        }
    }