/// <summary>
    /// Checks if the specified wave can be used in play mode.
    /// </summary>
    /// <param name="wave">A wave whose parameters need to be checked.</param>
    /// <returns>True if it can be used in play mode, false otherwise.</returns>
    public static bool IsWaveValid(Wave wave)
    {
        if (wave == null)
        {
            // The wave itself cannot be null
            return(false);
        }

        if (wave.waveElements == null || wave.waveElements.Count == 0)
        {
            // Wave must have an instantiated list wave elements
            // Wave must also have at least 1 element in the list
            return(false);
        }

        for (int i = 0; i < wave.waveElements.Count; i++)
        {
            WaveELement waveElement = wave.waveElements[i];

            if (waveElement == null)
            {
                // Wave element cannot be null
                return(false);
            }

            if (waveElement.enemy == null)
            {
                // Wave element's enemy cannot be null
                return(false);
            }
        }

        // Wave is valid and can be used in play mode
        return(true);
    }
示例#2
0
    private IEnumerator PlayWave()
    {
        int numberOfWaveElements = currentWave.waveElements.Count;

        spawnCooldown = new WaitForSeconds(currentWave.spawnRate);

        // Go through each wave element
        for (int i = 0; i < numberOfWaveElements; i++)
        {
            currentWaveElement  = currentWave.waveElements[i];
            shouldEnemiesAppear = currentWaveElement.chanceOfAppearing >= Random.Range(0f, 1f);

            if (shouldEnemiesAppear)
            {
                hasDelayBeforeSpawning = currentWaveElement.additionalSpawnDelay > 0;
                if (hasDelayBeforeSpawning)
                {
                    additionalSpawnDelay = new WaitForSeconds(currentWaveElement.additionalSpawnDelay);
                }

                // Get the exact number of enemies for this wave element
                numberOfEnemies = Random.Range(currentWaveElement.minNumberOfEnemies, currentWaveElement.maxNumberOfEnemies + 1);

                for (int j = 0; j < numberOfEnemies; j++)
                {
                    SpawnEnemy(currentWaveElement.enemy);

                    if (hasDelayBeforeSpawning)
                    {
                        yield return(additionalSpawnDelay);
                    }
                    yield return(spawnCooldown);
                }
            }
        }

        // All enemies in the current wave have spawned
    }