Boom! Boom! Boom! Let’s make an enemy's doom!

Let’s talk Explosions! Well…Tiny ones, anyway! Here’s a copy of the mini-boom sprite-sheet again in case you missed it from yesterday.

If you feel this sprite sheet would be useful to you, feel free to use it. I’m placing it under Creative Commons 4.0 w/attribution.

Here’s How it’s done!

import the sprite sheet into unity, make it a multiple, and slice it up. Then take all the frames and drag them into the scene. This will automatically create an animation for you, save the animation in the appropriate directory. Once you’ve done that, make this animated gameObject into a prefab and attach a Deactivation script to it:

this will turn the gameObject off, why not destroy it? Because we’re going to be saving a bit of memory and turning them back on over and over and over! You’ll see what I mean in a bit. This script actually makes it easier for us later so that we only have to worry about instantiating these explosions knowing they’ll take care of themselves once instantiated!

Place an empty in your enemy, I called mine MiniBoomHolder and we’ll create a script to attach to it that will generate a ton of mini-booms. I’ll call mine MiniBoomALypse.

The first variable is a holder for the parent object. We’ll be using it quite a bit figuratively when we instantiate the mini-booms and then attach them to the parent object.

We also create a holder for the mini-boom. It’s the same as the powerups and other animations. Just prefab the animation and drag it into the holder inside of Unity's inspector.

the next is how many minibooms we’ll be putting on the screen at any one time. 25 is actually too much, I ended up typing 8 in the inspector, though it’s really a matter of taste. You may want more.

the final variable is _apocalypse and it’s an array type. This will be holding all of the explosions that get instantiated.

In Start(), we define our _apocalypse variable to be the number of minibooms. then we use a for-loop to go through each slot in the array and we instantiate a new live mini-boom animation into it at 0,0 which will be the center of the enemy. Next, we parent the object to the enemy and turn it off. No need to explode until the enemy actually needs to be. And when we’ve filled up the _apocalypse gameObject array, we start the coroutine KeepOnBoomin.

This is essentially a repeat of the start function, but instead of instantiating, we’re turning the minibooms on. Remember the deactivation script we put on them? Well now we’re going to be going through each of the slots in the _apocalypse array and we’ll be turning them back on again but with even such a low amount of mini-booms like 8 like I’ve applied, it looks like way more!

Hope you enjoyed it! The next article will be about balanced spawning!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store