2D Galaxy Shooter P2: Wave System Initiated!

Gabriel Perez
2 min readMay 12, 2021

--

For today’s challenge, I implemented a wave system

I have to say this was the most challenging feature for me. It required a lot of thought and programming logic I haven’t fully developed yet. But in the end, it’s all working with tape and glue. It works, ladies and gentlemen! That is all that matters!

I was going to scratch the existing spawn-manager script I had, but instead, I went with keeping it and adding the wave system logic in there.

I created a custom class for the wave with a gameobject[], number of enemies, and the name of the wave fields. I also created public functions that return the game object array and number of enemies within the spawn manager class.

using UnityEngine;[System.Serializable]
public class Wave
{
[SerializeField] private string _waveName = “Wave 1”;
[SerializeField] private GameObject[] _enemies = null;
[SerializeField] private int _numberOfEnemies;
public int GetNumberOfEnemiesPerWave()
{
return _numberOfEnemies;
}
public GameObject[] GetEnemies()
{
return _enemies;
}
}

This script alone will enable me to create an array of “Waves” in the spawn-manager script so that I can create logic to iterate through each index. Thus, having each wave having its type of enemies and the amount of them as well.

So we can now create as many waves as we want with an increasing amount of enemies and types! It’s very flexible. It works in conjunction with the balancing/probability system I implemented not too long ago.

My biggest take on this is quite random. I have used the for loop for simple things, but for this, it kicked my butt. I learned that I had to create another, within a for loop, to access and iterate through the enemies game object array in the wave class. Once I figured that out on my own, It was a wonderful feeling!

That is all for today! Thank you for your time!

--

--

Gabriel Perez
Gabriel Perez

Written by Gabriel Perez

Hello everyone, My name is Gabriel Perez, I am a Unity Developer and a creator who is always learning and experimenting.