Day 41: Wave Manager with Unity Events (Part 1): 2D Space Shooter Series 09

Ted Lim
2 min readMay 28, 2021

In this article, we’ll cover how to use Unity Events to control the ordering of enemy waves from the Inspector.

Unity Events

The idea of a Unity Event is to signal when a certain method/behavior should be performed. A basic implementation example can be found here: https://docs.unity3d.com/ScriptReference/Events.UnityEvent.html.

What we’re interested in is how to give a designer more control over when these methods are performed. If you serialize a Unity Event, you can control which public method can be played.

Add the game object that contains the desired method you want to be executed, select the method, and voila! You’ve triggered an event.

An Array of Unity Events

Instead of triggering a single event, what if we triggered multiple events. In our 2D Space Shooter, we have a wave manager that needs to start certain waves of enemies at specific times.

We made multiple enemy wave types via public methods (SpawnWave01, SpawnWave02, etc…). However, we want the power to change the wave order easily as well. With an array of Unity Events, we have each event represent a SpawnWave method. We can then execute each method in order, and once a wave is completed, move on to the next event in the array.

Since the array of events is serialized, we can change the order of the events through the Inspector! The key to this setup is how to transition between each wave.

You must manually iterate through the methods in the array by determining when the previous wave is complete. Upon that wave’s completion, you’ll need to clean up the remains of the wave, move on to the next index in the array of events, and then Invoke() the next event to start the next SpawnWave method.

--

--