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…
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.
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.
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());
}
}
}
Have you check the Z index of the enemies as per the posts above?
There’s not a huge benefit in just zipping up some of your scripts as there are so many other potential issues which couldn’t be determined from seeing the scripts like this on their own. When sharing your code please copy/paste them into your posts and apply the code fencing characters (see below).
With bigger issues, like this one, please zip up your project and share it so that someone else can download it, open it and have a look, in context.
The forum will allow uploads of up to 10MB, if your project files (zipped) are larger than that you would need to use a service such as Google Drive or Dropbox, and then share the URL.