New Feature — Ammo Collectible

Objective: Limit the player’s ammunition, display the amount on-screen, and create an Ammo power-up collectible

Currently, in the game, our player can shoot unlimited bullets at the enemies. In this article, we are going to limit the amount of ammo the player starts with, ensure they think before they shoot and finally reward them with a way to refill their ammo supply.

Let's start with creating feedback on-screen to the player on how much ammo they currently start with, which is 15 bullets.

Create the Ammo UI

In this step, we will create the UI components which include a UI Image to contain the image (in my case 3 images) and a UI Text to show the Ammo count.

Firstly we create an empty object as a child of the Canvas, that is position top left and under the Thruster UI. Rename this empty to AmmoUI. Under this, create a UI Image and UI Text for the image and the text to show the ammo amount.

Ammo Count

UIManager script included the reference to the Ammo UI text, set the start to 0, and a method that the player can call to update the Ammo UI called UpdateAmmoText

When we play the game the Ammo display 0, yet the player can still shoot bullets regardless. We will limit this soon.

In the Player script, let’s store the ammo count and methods for the PlayerShoot script to call to check if there is ammo available and when to deduct ammo when it is shooting.

Now when we play the game, the ammo count goes down for each laser shot and stops when it runs out of ammo.

Create an Ammo Power Up

Since we have created modular type power-ups, we first need to add the Ammo type to the enum

Make a copy of an existing power up and rename it to AmmoPowerUp

Change the Power Up type to the newly added Ammo and a good time to change the sprite.

Now that we have the power up created, it’s time to add it to the Spawn Manager.

We are now ready to code what happens when the player picks up the Ammo Power up. Basically, we get it to call the UpdateAmmo method in the Player script and refill 15 bullets.

In the PowerUp script, add a new case to the Switch statement.

Play the game and when the player touches the Ammo Power up, it adds 15 to the ammo count.

If you enjoyed reading this article give me a Clap, also if you would like to see more, “Follow” me, so you may be notified of future releases. You may also send me a message if you need any further help.

A Data & Analytics Consultant who is expanding into developing experiences in XR, Enterprise and Gaming space using Unity www.jeannoelseneque.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Yik Yak is Not as Anonymous as You Think

Analysis of CVE-2019–11229 — From Git Config to RCE

Crio Launch Code Blitz: Experience

What and Why if __name__ == “__main__” in Python

How to get items side-by-side

Anti-Debugging Techniques

Writing technical articles: tips for programmers

The 9 Month Solo Development Journey of Skiwise

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
Jean-Noel Seneque

Jean-Noel Seneque

A Data & Analytics Consultant who is expanding into developing experiences in XR, Enterprise and Gaming space using Unity www.jeannoelseneque.com

More from Medium

Add a custom template to Unity for new projects

How should your game be designed to be fun?

Ice Kraken — Snowpiercer Fan Game

Getting started with using Unity