Nerd For Tech
Published in

Nerd For Tech

New Firing Powerup- Game Dev Series 40

Objective: Create new secondary fire powerup with rare spawn rate.

In this article, I will create a new firing powerup with rare spawn rate instead of triple shot.
As a new firing system, I want to create a firework-like shooting style with laser goes through 4 different direction after the main laser shot for 1 second.

Editor & Laser script

Create an empty gameobject and give it a name, this will be created when we shot the firework laser. Then drag in 4 laser prefab heading different direction.

Notice the heading direction. Since our laser will always go “up”, you should adjust the “up” heading to the direction you want.

Before the next part, we need to adjust the destroy method of laser script. So far we destroy the laser when it collide with enemy or the y-axis is over the top of our screen. Due to the new firework shot might not reach the top of our screen, it might would be a problem if we keep it that way.
As our new firing powerup, we need to destroy the laser when it runs out of screen area, which we can use a method to do that.

Open Laser script and create OnBecameInvisible(). This method would automatically destroy the laser when out of boundary.

Player script

Now we need to set the function of what should firework laser do when we fire it.
Open Player script and create some variables.

With these variables, we can create another “else if” in ShootLaser().

We created a laser gameobject to storage the laser prefab we shot. This will be the position that firework spawned. And also, we use Invoke to make the firework shot after the laser go for 0.5 second.
Then create the FireworkShoted() method.

With this method to fire firework laser, we need to create another public method to active the bool.

This method with coroutine is what we are going to call when we get the powerup.

The Player script should be done by now. Next part is the Powerup.

Powerup script

The Powerup setting would be easy, just call the method we just created with new powerup ID.

Now we can setting the “rare powerup” code.

SpawnManager script

Inside the spawn powerup routine, we will create a integer variable to count how many times that the triple shot were spawned. When the triple shot was spawned for 3 times, it will spawn a firework laser powerup.

We also need the change the random method of calling the powerup.

It should be -1, the firework laser one.

Then we can create a new if statement to replace the original spawning method.

When the triple shot called 3 time, the forth time would be the firework laser.

When the times reach 3, it will spawn the firework laser and clear the counts to 0.

That should be all. Back to editor and drag in all the prefab that needed. It’s time to test play.



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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.