Framework 1: Secondary Fire (part 2)

Having Secondary Fire Ammo pick up

Simon Truong
2 min readJun 13, 2021

--

Creating a secondary fire Ammo refill is very similar to the regular ammo pick up. You will need to have the Player Script, the PowerUp script and the Spawn Manager script. Along with some graphics representing the ammo container.

The Graphics

I just basically taken a basic container that I added some animation to, along with the text “Special” to let the player know that this ammo will be for the special weaponry. I attached a Box Collider and Rigidbody2D to the component along with the PowerUp script.

The Player Script

In the player script, since we have already created the initial method class for the special ammo, all we need to do is to make sure that when the player collections additional ammo that the ammo count doesn’t over exceed 3.

The special ammo is capped at 3 shots total and if the player collects an new container, the UI manager will update.

Then add the else statement that _specialPower should be additional or equal to the integer count of “beams.” We can reference the amount of beams within the Power Up script.

The Power Up Script

Just like any other power up additions, we add the new power up by using the same system. Create a new case logic within the switch statement and have the statement reference the player class then calling the “Special Beam Count” method. In the brackets state how many beam reloads the container should give the player. In this example, I used 3, since I wan the player to get the maximum refill per pick up.

The Spawn Manager

In the spawn manager, we need to update the amount of instantiated properties from 5 to 6 to include the newly created special ammo.

Finally in the Spawn manager inspector, you are going to drag and drop the special ammo prefab into the newly created slot so the spawn manager has access.

--

--

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.