Enemy Waves Spawner

I’m going to talk something about how I created an enemy waves spawner. Before this, there were only two types of enemies come out from the left screen in our game, and the enemies just keep doing this forever. In a traditional “shoot ’em’ up” game, enemies always come out with different waves, for example, there is only one enemy in the first wave, then two enemies in the second wave, then maybe five enemies, and so on.

In order to do this, I created a custom class called wave, and inside this, I had a couple of variables, like the names of the waves, a game object, and the amount of enemies. Before I code this class, I need to have [System.Serializable] at the beginning, basically what this does is simply allow us to change the values of this instances of this class inside of the Unity inspector. In the update, I needed an if statement just for help me to count down the time between two waves. When the time hits zero, then it will check if it is already spawning. If it is not, it is going to loop through the amount of enemies that I want to spawn and for each enemy that I want to spawn it will call the spawn enemy method which is going to instantiate enemies. I used an IEnumerator and the reason for this that I want to be able to wait a certain amount of seconds inside of the method.

I also needed a function to check if there are still enemies alive, so I created a bool called EnemyIsAlive. Inside this, I did a very simple check. I have used GameObject.FindGameObjectsWithTag and then I gave all enemies a tag “Enemy”, and this will return an array of all enemies, or all game object with this “Enemy” tag. So if the array’s length equals to zero, well then there were no enemies anymore, then return false. If not it will return true.

Enemy Waves Spawner”的一个响应

  1. It’s a bit difficult for me to grasp how the wave spawner is structured based on your text. You’re going into details about the functions and variables you’re using, but it’s hard for me to see the whole picture. You shouldn’t have to go more technical than you already are, but some sort of short overview of the functions and how they work together could make it easier to read. Also, you should really add some description to your images, as they aren’t really explained in the text itself.

    I know by reading your blog post how the wave spawner works, but I haven’t seen the end result. A video, a gif or even just a still image of the wave spawner in action would make it more relatable, because then I can also see how it works.

    You’ve got the technical details, but I’m missing your design decisions and personal analysis of your work. You briefly mention how the “traditional” spawner works and that it’s what you’re going for, but I also want to know why you chose that instead of another solution. Also, some reflections on the functions you’re making: Were there any complications in the creation of the wave spawner? Did you do this iteratively, and if so, how did you improve it from the previous versions? Did you learn something interesting that you want to share?

    To sum it up, your blog post could do with more of your personal experience regarding the topic. You’re explaining your work in detail, but I’m also interested in hearing your struggles and your own opinions of the result. Add your own personal flair to it.

    Best of luck with your project!
    ( ^◡^)

    Liked by 1 person

留下评论