In this short article I’m going to walk you through on how the SimpleWaveSystem project works.
The Unity project is very easy to navigate; it was done using Unity 2019.4.29f and in the Hierarchy windows we have a GameObject label WaveSystem that holds the necessary GameObjects that have the scripts to control the wave and a simple UI Canvas to display some text and buttons to start and restart the wave.
On the project window there’s a folder named SimpleWaveSystem, this folder has all the scripts, scriptable objects and basic enemy game objects to test and make the wave system work.
The script itself has a class called WaveSetUp, inside a class we have a public int property that will hold the ID of the GameObject you want to spawn and a public GameObject property to hold your Enemy or item game object.
This class is turned into an array by calling it in the WaveSystemSO that inherits from ScriptableObject. By creating this array you can control what types of items or enemies are created on a specific wave and how many. We have an int that will determine how many items or enemies are being spawned in this wave.
Have in mind that regardless of how many objects you’re using on the wave if the amountToSpawnOnThisWave variable is not higher than the items, all the items will not be used.
The ReturnObjectType() method will be called by the SpawnManager; the method will return the ID of the object and the SpawnManager will use this ID to call the necessary object from the PoolManager.
This script is where you’re going to hold the reference of each wave you create. The WaveSystemManager is the one that is going to share the necessary properties to the PoolManager and to the SpawnManager. By having just one script to share this type of data you can change the wave at any giving moment and the system will still work.
The PoolManager is going to create a list of the necessary objects you put on the waves; this list is put inside a Dictionary, it will use the objects ID to use it as the Key Reference to later call a specific list object. For each list the PoolManager will create 20 of each object, by doing this the SpawnManager will spawn the object of the select list. Keep in mind that you can change the pool size on the script; if you increase the spawn item on the wave and it is higher than the pool size you must increase the pool size.
The SpawnManager is the one that will call the object using the PoolManager and it will also control the time between each spawn object or the time between each wave. This script controls the position on where you want the object to spawn; you can change the position to your linking using the public method called ObjectPositionToSpawn().
How To Create Waves?
Right Clicking on the Project Window -> Create -> Rehtse Studio Simple Wave System -> Create New Wave
Assets -> Create -> Rehtse Studio Simple Wave System -> Create New Wave
Hope you like the repo, if you see something strange or a error please let me know and you can make whatever changes you want on the code😁
To be continued 😎