Creating Enemy Explosions

Ameen Mohmand
3 min readMar 17, 2024

--

Objective: How to make the enemy explode:

Today were gonna learn the necessary steps to make are enemy explode. The first thing we need to do is create our explosion animation for our enemy first. To do that lets go to our look dev view on our enemy prefab. Now click on open in the inspector to see the enemy look dev view. Lets get out of the game dev view for the enemy. Next with our enemy selected lets create the enemy animation. Now lets go to the animation window and now click on create and now lets click on our animation folder and rename it to Enemy_Destroy_anim. The next step lets open up our animation sprite for our explosion and drag it into our animation window by selecting the whole explosion animation sequence. Now you will see by clicking the play button the enemy animation explode. If you have noticed is that the enemy explosion animation is constantly cycling, it shouldn’t be doing that. To fix this issue were going to have come up with code to stop it from exploding constantly. The question now becomes how do we program it to stop, first you must turn off looping, let’s give a try. To do that you must go to animations in our project window and click on it then select Enemy_ Destroyed, once you do that uncheck the box for Loop time. If you notice the controller is still telling the explosion animation to play and that's not what we want. Now if we look inside the explosion animation controller we will see that if we double click on it, it will take us to the animator view. Now inside the animator view you will see Enemy Destroyed _anim in orange, and the reason its orange because its the default state. As long the default state is active its gonna play the animation in that state. So now we have to tell Unity to settle down and play that animation when its time. To do that we need to create an empty state, by right clicking and selecting empty state. Now click on the empty state in the animator window and then head over to the inspector and rename it from new state to empty state. The following step were gonna set it as the default state. Please save your scene and now lets run it in Unity. One thing your gonna realize is that empty state is not running the explosion animation and your enemy is not exploding on contact now when it collides with the laser. The reason for that is because we will decide when the empty state should transition to the explosion animation. So now we have to tell it when to explode and the way we do that is through parameters. So the four parameter that we can choose from are float, int, bool, trigger. From the following four variations of parameters we gonna choose the trigger parameter logic that were gonna call on enemy death so it can cause our enemy animation explosion death. So were gonna right click on the transition line its gonna bring it up in the inspector, lets click on settings in the inspector and it has some conditions which we can choose from and were gonna select our on enemy death animation so we can have our enemy animation explode. Stay tuned.

--

--