Feeling Like A Real Video Game!- Game Dev Series 15

Objective: Add a powerup object.

Previous: Benefits of Prototyping Without Assets

Mostly, a game would become harder and harder. To handle that situation, we usually get a powerup stuff during game.
It is time to add some buff to our Player. Let’s make a triple shot powerup.

First, create an empty and name it “Triple_Shot_Powerup”. Then store our laser prefab in it.

Don’t forget to make the position at 0

Then adjust the position of 3 laser in the powerup.

Drag the powerup into project window to make a prefab, and open the Player script. We need to make our player get triple shot when collect the powerup object.
First, create a variable for Triple_Shot_Powerup,

Then we need to set a bool to check if the powerup active or not. To demonstrate this function, we add a SerializeField for now.

Go to the function which handle the shooting, and add another if-statement.

We use this bool check to tell our Player give 1 shot or 3 shot.
Back to Unity and drag the Triple_Shot_Powerup prefab into the slot.
Let’s see the result.

Next, let’s create a powerup object.

Drag the triple shot powerup sprite into hierarchy. Due to make this contactable with player, we need to give it the basic collision pack: Collider & Rigidbody.

Don’t forget the gravity scale & isTrigger

Then make it drop down to the game scene and Player could get triple shot when collide with it.

Let’s add another function of active the triple shot to Player script first.
We need this function to switch the value of bool.

Create a new C# script called Powerup, then add a drop down motion to it like enemy.

Then add an OnTriggerEnter2D to it to call the TripleShotActive(). And also make this gameobject destroy when collide.

Make a null check to prevent error

Play again to check the result.

Next, let’s attach our triple shot powerup to Spawn Manager.

Open SpawnManager script and add a SerializeField variable to store the powerup prefab.

Then we can add an IEnumerator to spawn it.
The code is familiar as SpawnEnemyRoutine() but without setting the parent when spawning.

I make a random time to this routine

And also add a line to Start().

Back to Unity and drag the powerup prefab to the slot, then we can check if it works.



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.