Bring out the Big Guns with a New Powerup!

addam davis
4 min readJun 24, 2021

--

Objective: Create a powerup to activate a new firing type.

On this journey I’ve already done a tutorial for a triple shot powerup where the player shoots three shots instead of one. Today, we are going to create a powerup to give a new firing type, the big shot. A wide shot that destroys everything it touches. To begin we need to create and prefab a sprite for the big shot.

I took my sprite I used for the regular laser, changed the color a scaled it along the x axis to make it wide.

We also need to create and prefab a sprite for the powerup for this special laser. I use a scaled down version of the big shot. We need to add the collider and rigidbody and the powerup script. Add the powerup to the spawn manager inspector and give the powerup an ID#

Open the powerup script and add the powerup to the switch statement. Open the player script and create a method for the powerup to call when collected.

Now we need to set up a bool variable for the powerup to switch when called.

Then we need to set up a cooldown system like the one we used for the triple shot.

Now we have a system in place for the powerup to activate for a set amount of time and return to normal when it’s done. Now we need to set up what the powerup does.

We need to go to the player script and under the method that controls what the player shoots. Add an if statement for when the big laser variable is true the player instantiates the big laser instead of the normal laser.

This is a big weapon but how in its current state we need to create a tag for the big laser.

In the enemy script we need to add the new tag to the OnTriggerEnter and add the code for what the enemy does when it collides with the big laser. we want it to do the same as the regular laser, however we don’t want the big laser to be destroyed on contact, we want the big laser to pass through the enemies and hit those behind it as well.

This is a powerful weapon, so we want to limit how often the player can access this powerup, so we are going to the spawn manager script, and we are going to create a new IEnumerator for rare powerups. We are going to use the same formula as the other two routines, only with larger wait times.

This way you can control what powerups spawn more frequently, and which spawn rarely.

This is all there is to it. You now have a third type of firing, and a rare spawn rate for your powerups. You can add other powerups to the rare spawn rate and vice versa, depending on what you like. Don’t be afraid to experiment with your code, and I’ll see you in the next tutorial.

--

--