Explosions!

Josh Vang
3 min readMay 8, 2021
An explosion of epic proportions

In entertainment, explosions is used in many different scenarios. For instance, it could be used to represent death of an object, from the villain to mere oil barrels that happens to show up in the right time. On the other hand, it could also be used to represent the start of another scene. Regardless of how explosions are used, they tend to imprint a strong action based, fast-paced emotion onto the audience. And lucky for us, in Unity, it’s pretty simple to create them.

Setting up a Sprite-based Explosions

This type of explosions are easy to set up, although initial step does take some time as it requires each frame of the explosion in order for the explosion to process correctly. Once each frame is imported into Unity, we can create an animation for it using the Animation window built into Unity.

A total of 157 frames created for this explosion

Place the first frame into the Hierarchy and then, in the Animation window, create a new animation by clicking on Create

After you name your animation, Unity will also generate an Animator for you and place it on the frame you just placed into the Hierarchy. Drag all the frames of the explosion into the Animation window and save.

All the frames added!

You now have your very own explosion. All that’s left to do is convert this object into a prefab so you can reuse it anytime you want.

However, after creating the animation and an animator for the explosion, it’s time to jump into code to execute the explosion so it can play on your command.

Coding your Explosion to play

Because the Animator is already added onto the game object you just created, all you need to do is tell Unity to play the animation. If all you’re doing is play the explosion once the game object is created, the code will be as simple as this:

Essentially this one line of code is telling Unity to destroy the object, the explosion in this case, after 3 seconds has lapse.

You might wonder how the animation will play if all we do is just destroy the object. Well, because the object already has the explosion animator attached to it, as long as we set it to play on awake, it will play once the game object is created.

Other notes

If you don’t want the explosion to keep looping after the first explosion, find the explosion animation and look at its properties in the Inspector Window.

Just uncheck the box next to Loop Time and done!, the animation will only play once and it’ll stop.

--

--