コード例 #1
0
 protected virtual void OnWaveChanged(WaveEventArgs e)
 {
     if (WaveChanged != null)
     {
         WaveChanged.Invoke(this, e);
     }
 }
コード例 #2
0
        private void StartWave()
        {
            WaveStatus = WaveStatus.InProgress;

            _waves[Level].Spawn();

            WaveChanged?.Invoke(this, EventArgs.Empty);

            Level++;
        }
コード例 #3
0
        public void InitializeWavesManager()
        {
            SetWavesFromChildren();
            foreach (var wave in Waves)
            {
                wave.InitializeWave();
            }
            DisableWaves();

            Target.Instance.TargetDestroed += RestartLevel;
            Wave.EnemiesAllKilled          += ChangeWave;


            Waves[0].gameObject.SetActive(true);
            WaveChanged?.Invoke(Waves[0].Enemies.Count, currentWave + 1);
            Waves[currentWave].SpawnEnemies();
        }
コード例 #4
0
    private void Update()
    {
        for (int i = enemies.Count - 1; i >= 0; i--)
        {
            if (enemies[i] == null)
            {
                enemies.RemoveAt(i);
            }
        }

        var guns = Random.Range(0, difficulty);


        if (enemies.Count == 0)
        {
            var gunSlotsTaken = 0;
            difficulty++;
            Resources.UnloadUnusedAssets();
            System.GC.Collect();
            WaveChanged.Invoke(difficulty - 2);
            var random01 = Random.value;
            //flying round
            if (random01 < 0.2f)
            {
                foreach (var spwn in Spawns)
                {
                    for (int i = 0; i < difficulty / 2; i++)
                    {
                        var enem     = Instantiate(EnemyPrefab1, spwn.position + Vector3.up * difficulty * 2.0f, Quaternion.identity);
                        var enemComp = enem.GetComponent <EnemyBase>();
                        enemComp.Init(difficulty);
                        enemies.Add(enemComp);
                    }
                }
            }
            //ground round
            else if (random01 > 0.5f && random01 < 0.8f)
            {
                foreach (var spwn in Spawns)
                {
                    for (int i = 0; i < difficulty / 2; i++)
                    {
                        var enem     = Instantiate(EnemyPrefab2, spwn.position, Quaternion.identity);
                        var enemComp = enem.GetComponent <EnemyBase>();
                        enemComp.Init(difficulty);
                        enemies.Add(enemComp);
                    }
                }
            }
            //mixed round
            else if (random01 >= 0.8f && random01 < 0.95f)
            {
                var ratio = Random.value;
                foreach (var spwn in Spawns)
                {
                    for (int i = 0; i < difficulty / 2; i++)
                    {
                        GameObject enem;
                        if (Random.value < ratio)
                        {
                            enem = Instantiate(EnemyPrefab1, spwn.position + Vector3.up * difficulty * 2.0f, Quaternion.identity);
                        }
                        else
                        {
                            enem = Instantiate(EnemyPrefab2, spwn.position + Vector3.up * difficulty * 2.0f, Quaternion.identity);
                        }
                        var enemComp = enem.GetComponent <EnemyBase>();
                        enemComp.Init(difficulty);
                        enemies.Add(enemComp);
                    }
                }
            }
            //gun round
            else
            {
                for (int i = 0; i < difficulty; i++)
                {
                    if (GunSpawns.Length > i)
                    {
                        var enem     = Instantiate(EnemyGunPrefab, GunSpawns[i].position, GunSpawns[i].localRotation);
                        var enemComp = enem.GetComponent <EnemyBase>();
                        enemComp.Init(difficulty);
                        enemies.Add(enemComp);
                        gunSlotsTaken++;
                    }
                }
            }

            for (int i = gunSlotsTaken; i < guns && i < GunSpawns.Length; i++)
            {
                var enem     = Instantiate(EnemyGunPrefab, GunSpawns[i].position, GunSpawns[i].localRotation);
                var enemComp = enem.GetComponent <EnemyBase>();
                enemComp.Init(difficulty);
                enemies.Add(enemComp);
            }
        }
    }