Unity : TD Wave Spawning & Editing Scripts

I wrote two c# scripts to handle wave creation and spawning in a tower defense game.  A wave spawning script and an editor script.

Let’s begin with my wave spawning script.  I stored each wave’s info (enemy, spawn point, spawn number, spawn delay, etc.) in an object.

I packaged a collection (list*) of these objects into a class that implements the IEnumerator interface so I could easily enumerate through a level’s waves.

Once the level is loaded I kick-off a coroutine to handle spawning, and passing the appropriate references to our spawned enemies

Now that I had a script to spawn enemies I needed a way to easily assign values.  For this I wrote an Editor script.  Remember these  must always be placed in a projects Editor folder.


Script below:

Hope this was helpful.  Comments are always appreciated.


*For simplicity I used a list instead of an array.  I put this list of WaveObj’s (even though it is an enumerable) inside WaveEnumerator so I could handle wave size (count) inside of the Unity IDE.

One thought on “Unity : TD Wave Spawning & Editing Scripts

Leave a Reply

Your email address will not be published.