About 'Loop All Enemy Waves'!

cud_s06_loop_all_enemy_waves

#1

In this video (objectives)…

  1. Turn our Start method into a coroutine.
  2. Create a looping bool.
  3. Create a do while loop that allows us to loop all waves over and over.

After watching (learning outcomes)… Loop all of our enemy waves using a do while loop.

(Unique Video Reference: 18_LD_CUD)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!


#2

Still rough and just an endless run of random waves, but I figured I would actually try sharing occasionally as I go along on this one. The stone tablet I’m carving the game on took 30 minutes to process the build even at this primitive stage. It’s been a real deterrent to sharing progress.

Was wondering if there was some way to limit the view on Web GL builds to just what the camera sees. Rather than letterboxing and pretending the area outside the camera doesn’t exist it’s, behaving more like the scene editor and displaying the entire area.


#3

Got everything working. I had a problem with the EnemySpawner not recognizing one of my paths. Turned out I had not reset that path’s transform values to 0’s. Once I did that it worked fine.


#4

I comment the heck out of code that I’m working to understand. I’m hoping some of the more experienced programmers here might review my comments and let me know if I’m understanding this code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// class whose purpose is to spawn enemies List values for waves
public class EnemySpawner : MonoBehaviour
{
    // class: List, type: WaveConfig - create EnemySpawner.waveConfigs field 
    [SerializeField] List<WaveConfig> waveConfigs;
    [SerializeField] int startingWave = 0;
    [SerializeField] bool looping = false;

    // IEnumerator makes our Start method a Coroutine
    IEnumerator Start()
    {
        // while looping true spawn waves
        do
        {
           yield return StartCoroutine( SpawnAllWaves() );
        }
        while (looping);
    }

    // populate indexed List data of type: WaveConfig
    private IEnumerator SpawnAllWaves()
    {
        // count/index waves, return all List values respectively for all waves
        for ( int waveIndex = startingWave; waveIndex < waveConfigs.Count; waveIndex++ )
        {
            // assign indexed List values to a variable
            var currentWave = waveConfigs[waveIndex];
            // return List values for each indexed wave
            yield return StartCoroutine(SpawnAllEnemiesInWave(currentWave));
        }
    }

    // populate List data of type: WaveConfig through param waveConfig
    private IEnumerator SpawnAllEnemiesInWave(WaveConfig waveConfig){

        // fill List with data
        for (int enemyCount = 0; enemyCount < waveConfig.GetNumberOfEnemies(); enemyCount++ )
        {
            // create data to Instantiate new enemy at a position
            var newEnemy = Instantiate(
                waveConfig.GetEnemyPrefab(),
                waveConfig.GetWaypoints()[0].transform.position,
                Quaternion.identity);

            // pass this newEnemy data into waveConfig param of SetWaveConfig()
            newEnemy.GetComponent<EnemyPathing>().SetWaveConfig(waveConfig);

            // return waveConfig data after waiting timeBetweenSpawns
            yield return new WaitForSeconds(waveConfig.GetTimeBetweenSpawns());
        }
    }	
}

#5

Same thing happened to me. A huge “d’oh” moment when I realized one wave was at a higher Z index.