Creating Enemy Explosions In Unity

Having enemies in a shooter game is kind of essential. Getting rid of those enemies when you shoot them is also essential. So how do we make it interesting? Well, we could always make them explode!
Mission: To create enemy explosion when enemy is destroyed.
So, how do we go about doing this? Well, for starters you need to create an animation. I’ve written several articles on how to create animated sprites so I won’t delve into too many details on that in this article.

Then you just have to program when you want to trigger the animation in your code. So start by making a public or serialized animator to get the animator component from your object if the script is not on your object. In my case it is on my scripted object so I can just make it private and get it.

Get the object in start() and make sure you do a null check to get rid of any errors for null reference exceptions.

Then create a method for triggering the explosion animation. In my method I set my animation trigger, turn off the collider of my destroyed enemy ship because I don’t want it to collide with anything anymore because i8t is destroyed, and stop it so it doesn’t jump back to the top of my screen because it looks funny.

Then you can call that method wherever you want your enemy explosion to happen. Pretty easy setup.

Thank you for reading =).

