Create Ammo Count Feature in Unity

Showing current ammo to the player

Objective: create an UI Text element to show the current ammo during the game

In the player script declare an Int variable to represent the max ammo player can have and a get method to access to this value.

In the add ammo function we are gonna add a condition to check if ammo is greater than max then we set the ammo with the max value.

In the UI manager in the update ammo function we have to add a new parameter to receive the max ammo value and add it to the text.

And that’s it! The ammo is shown in the current/max format.