예제 #1
0
    void NextWave()
    {
        if (WaveInProgress)
        {
            Debug.LogWarning("Can't start new wave, current one is in progress");
            return;
        }

        _currentWaveIndex++;
        if (_currentWaveIndex >= Waves.Count)
        {
            if (InfiniteWave != null)
            {
                StartCoroutine(InfiniteWaveRoutine(InfiniteWave));
            }
            else
            {
                Debug.LogWarning("No more waves");
            }
        }
        else
        {
            CurrentWave = Waves[_currentWaveIndex];
            StartCoroutine(WaveRoutine(CurrentWave));
        }

        NewWaveStarted?.Invoke();
        SoundManager.Instance.Play(WaveStartedSound);
    }
예제 #2
0
    private void Update()
    {
        int enemyAliveCount = FindObjectsOfType <Enemy>().Length;

        if (enemyAliveCount == 0 && currentWaveSize == 0)
        {
            if (isCurrentlyWave)
            {
                CurrentWaveEnded?.Invoke(this, new SpawnControllerEventArgs(this));
                timeUntilNextWave = timeBetweenWave;
                isCurrentlyWave   = false;
            }

            timeUntilNextWave -= Time.deltaTime;
            if (timeUntilNextWave > 0)
            {
                return;
            }

            currentWaveSize = Random.Range(GetNewMinWave(), GetNewMaxWave());
            isCurrentlyWave = true;
            NewWaveStarted?.Invoke(this, new SpawnControllerEventArgs(this));
            timeUntilNextSpawn = 0;
        }

        if (!isCurrentlyWave || currentWaveSize == 0)
        {
            return;
        }

        timeUntilNextSpawn -= Time.deltaTime;
        if (timeUntilNextSpawn > 0)
        {
            return;
        }

        int objectIndex   = GetRandomSpawnObject();
        int locationIndex = GetRandomSpawnLocation();

        GameObject enemyGameObject = Enemy.Create(spawnObjects[objectIndex], spawnPoints[locationIndex].Transform.position, playerController);

        enemyGameObject.transform.SetParent(spawnParent.transform);

        --currentWaveSize;

        timeUntilNextSpawn = Random.Range(GetNewMinTime(), GetNewMaxTime());
    }