“Funslingers” Devblog #27 | Creating Ammo Refill Powerups in Unity

Ethan Bristowe
Everdevs Community
Published in
4 min readSep 8, 2021

Hey Devs!

Now that we’ve made an ammo feature for our game where our player can potentially run out of bullets, we’ll need to make a way for our player to get some ammo back! Introducing… The Ammo Powerup!

This nifty little guy will refill the player’s revolver full of bullets in no time at all! And lucky for us, implementing this feature is now easier than ever!

To create this Ammo Prefab, all it took was just an empty gameobject was just the same Box Collider and Powerup script as all our other powerups, along with it’s custom Ammo Icon.

Then, adding it to our Spawn Manager took no time at all, added it’s variables to the script then created another else if statement to instantiate it the same way as our other powerups.

And lastly, the easiest part in our Player script, once the player collides with the powerup, simply refill the player’s ammo, update the Ammo Counter and let the player shoot again!

BOOM, and we’re done! That’s the magic of making modular, simple systems as it allowed us to essentially plug and play this new feature in just a couple of minutes!

We could absolutely call it a day here, but I actually want to give our Ammo feature a bit more depth. I’m gonna create a second Ammo Powerup that will be dropped by dead enemies!

This one will only be worth 6 rounds instead of 12 so let’s make a powerup prefab that will represent a smaller refill.

Sweet! Next, we’ll child this Prefab to the Enemy Prefab, and also make a different Powerup Script that will Instantiate the object from where the Enemy’s body is.

Easy stuff! Now, we’ll grab this prefab from the Enemy Script and Activate it once the enemy dies.

I created a local variable and used Random.Range to create a 50/50 chance that the enemy will drop some ammo before they are destroyed, as well as nullified the prefabs parent so it doesn’t get destroyed with the enemy, it will fly along on it’s own!

And lastly, just like our first Ammo Powerup, one the player collides with it, it will refill the player’s ammo count!

The difference here, is that it will only add 6 rounds, and to keep it capped at 12, I have a simple if statement to keep the ammo at 12 no matter how many ammo drops the player gets.

And that’s it! What started as a simple Ammo Counter, became a huge part of our game creating an aspect of strategy needing to conserve ammo and require to be more accurate with shots!

In the next devblog, we are gonna create another replenishing powerup for the player’s health!

--

--

Ethan Bristowe
Everdevs Community

Passionate self taught game developer excited to learn and share everything I can about game development!