I’m trying to create a tower defense like wave spawner, and am looking for the best approach to make a non-random series of spawns on a set timeline. Every post or tutorial I’ve found on the subject seems to be based on random enemies, positions, and intervals.
I have 3 normal enemy types, 1 boss type, and want to have them spawn in a specific pattern (i.e.: after 3 seconds spawn 1 of enemy A, after 5 seconds spawn 2 of enemy B, etc).
Right now the spawner I created is throwing out random enemies at random intervals. I feel like I could pretty easily make a long script that has a bunch of IEnumerators set to spawn each type on each time, but that seems like a poor approach that would be error prone scale poorly.
What I’d like is something in editor where I can add an arbitrary number of fields, one for each spawn, which specifies the enemy type and time of spawn, so I could rapidly play around with timings in editor, as opposed to needing to jump back and forth between scripts, or instead of placing a ton of individual spawner game objects. I guess I want to make an array with multiple pieces of data for every entry, or something like that.
For reference, I’m using C# and am pretty much totally new to programming. Any advice for how I should approach this would be appreciated. Even just what I should be searching for, as I suspect I don’t even know the right terminology.
float timer = 10;
int phase = 0;
void Update()
{
timer -= Time.deltaTime;
switch(phase)
{
case 0:
if(timer <= 10)
{
//spawn first set of enemies
phase = 1;
}
break;
case 1:
if(timer <= 5)
{
//spawn second set of enemies
phase = 2;
}
break;
case 2:
//etc, just continue this pattern
break;
}
}
Here, try out this video. I used the system laid out in it for a long time until I needed to get a little more complex. Works perfectly, and the video takes you through the whole thing line by line so its great for a new user. All the other videos on the series are good to watch too, you can learn alot of good things from them.