2D Shooter: Triple-Shot Powerup!

Sabrina Windsor
2 min readJun 13, 2021

--

It’s time to add some powerups to the game! They come in handy when you might be swarmed with enemies and the single laser won’t cut it on its own. It also brings a player more satisfaction when playing by getting that boost of power!

Objective: Create a prefab for a triple-shot powerup and instantiate it.

For now we won’t worry about the collectable that would activate it, let’s just focus on the power up itself.

First, we’ll want to create an empty object, name it “Triple_shot”, and copy three lasers into it as children.

Once that is done, place the three lasers where you want them to appear in the scene view. Then drag the Triple_Shot down into the Prefab folder.

Now in the player script, we want to create a new gameobject variable “_tripleShotPrefab”, and a bool variable “_isTripleShotActive”. Set the bool to false. Both of these should also be accessible in the inspector.

Drag the triple shot prefab to the box in the player’s script component.

We now want to create and if/else statement in the FireLaser() method. It will basically say that if tripleshot is activated, then it will instantiate the tripleshot prefab instead of the regular laser. Otherwise, it will instantiate the regular laser.

The code will look like this:

And thanks to the bool variable we made above, the code can check if this is set to true and can activate the triple shot. For now you can make the bool true by clicking the box in the player script.

And we’re done!

--

--

Sabrina Windsor
Sabrina Windsor

Written by Sabrina Windsor

Currently learning to code with the help of GamedevHQ in order to someday my my game ideas come to life!

No responses yet