Spawning enemies every once in a while
|
This weeks asset is a script used to spawn enemies in different waves. This script was written in order to allow a continuous stream of enemies to reach the player, whilst also allowing for different combinations of challenges throughout the game. The way the script is currently set up allows the user to create a set amount of waves, with each wave containing their own variables. The variables that each wave hold are as follow:
In order to make this chaos of a script more manageable I spent a significant amount of time working on a custom editor to change the Unity interface. This custom editor is a script that derives from Unity’s editor, overwriting the onInspectorGui() function and allow for variables to only be shown when they are needed. An example of this is how the user can not fill in an amount of enemies after which the wave is completed unless a boolean variable is flagged as true in the inspector. This custom editor also created a big problem though, to counter the positives. The problem in question was that I found no perfect way to allow each of the waves to keep track of the enemies available since there could be multiples. ![]() Two downsides with the current rendition of the script is that it is unable to spawn multiple waves at once, and it does not let the user reorder the waves after creation. The former of these two can as of now be solved by adding multiple instances of the script as components to the gameobject in control of creating the enemies. As for the latter problem, I do believe there is a way in Unity to make arrays able to be reordered, although the current script does not allow it. The reasoning behind the script holding all of these values is that the group wanted an alternative to only setting the type of enemy and its spawn, which would result in a constant stream of only one challenge. |
