Adding the first Official Powerup™ — Triple Shot

We’ve upgraded our game from a 3D prototype to a beautiful 2D Space Shooter! Now it’s time to really utilize these assets and get our game looking and feeling like something great!

And what’s an arcade-y Space Shooter without a some fun Powerups!? Let’s get down to business and destroy multiple enemies with our Triple Shot!

Pew! Pew! Pew! (x3)

Create the Triple Shot

We’ve converted our Laser capsules into proper looking Laser Beams. So the first thing in creating our Triple Shot Powerup is the placement of the 3 lasers!

We’ll drag 3 laser prefabs into the Scene Hierarchy and place them as such:

Triple Shot Placement

Then with our lasers placed properly, we’ll throw them into an Empty Game Object — Triple Shot, and create a Prefab!

Creating the Triple Shot Prefab.

Linking the Prefab with the Player script

Now in our Player script, we’ll create a handle for the Triple Shot since this is where we’ll be Instantiating the Triple Shot from, just like the previous single Laser.

The bool we will use soon. The GameObject _tripleShotPrefab is our handle.

And we can’t forget to link our Triple Shot Prefab to our updated Player script:

Linking the Triple Shot Prefab to the Player script.

Next we can update our FireLaser() function utilizing the bool we created for the Triple Shot, _tripleShotActivated.

Updated FireLaser function.

Activation Prep

Quickly before we can activate our Triple Shot, we’ll create a function to Activate the Triple Shot when called. And with it, a Coroutine to give the Powerup a limited timeframe to be used; or else it could go on indefinitely.

ActivateTripleShot function, and TripleShotCooldown coroutine.

Creating a Global variable for the amount for the Triple Shot Cooldown:

Cooldown variable created.

Activating the Triple Shot

Currently we have no way to activate the Triple Shot, other than clicking on the box in the Inspector during run-time. So up next we’ll create the collectible Powerup item to activate the Triple Shot!

I’ve dragged a Triple Shot Powerup Sprite into my Hierarchy, and will have to give it a Box Collider 2D and make it a Trigger collider so that our Player can interact with it:

Triple Shot Powerup fixing the Box Collider 2D.

Then to give this Powerup Sprite functionality, we’ll create a Powerup script. In the Powerup code, we’ll give it some basic movement:

Basic Powerup movement code.

And some collision logic:

Now we can connect our Powerup script to our Triple Shot Powerup and make it a prefab:

Triple Shot Powerup prefabbed
Triple Shot Functionality! Those enemies don’t stand a chance now! For 5 seconds at least…

Perfect! Our first Powerup! Remember, you can always tweak different variables to make them feel how you want for YOUR game. Every game should feel a little unique!

We still have a little bug in our code, but we’ll fix that in the next article! Then we’ll create another Powerup!

Audio Engineer turned Unity Game Dev. Will be combining both my skillsets when appropriate, and will be documenting my Unity Dev growth in these Medium Articles