Creating the Ammo Refill Collectible

Sherry Fisher
3 min readDec 1, 2023

--

In my last article, I had limited the player’s ammo count to 15. Now I need to devise a way for the player to be able to refill their ammo.

First I create my ammo powerup using GIMP and import into Unity. I make several with different colors of text in order to animate it.

As with previous powerups, I drag the new powerup to the hierarchy and adjust the scale. I then add the collider and edit it to match the size of the powerup and check the IsTrigger box. I add the Rigidbody component, making sure to set gravity to 0. I then set the Sorting Layer to foreground.

Next, I assign the powerup script to the new powerup and set the powerup ID to 3.

I create the animation for the new powerup.

Once the powerup is all setup, I remove it from the hierarchy and add to the prefab folder and add it to the Spawn Manger in the Inspector.

I update my Player script by adding in an AmmoPowerup method that returns ammo count to 15 when powerup is collected and updates the UI.

I update the switch statement in my Powerup script to call the AmmoPowerup method and then adjust the range in the SpawnManager script.

I add the powerup audio clip to play when the powerup is collected.

Upon testing, everything works except the empty ammo audio clip continues to play after the player has collected the powerup and the ammo has been refilled. I adjusted the FireLaser method to account for the different sound effects. I am not sure if this is the best way to do it, but it is working now, so I am happy with that.

Now the player can refill their ammo!

--

--