Simple limited ammo system

Let’s have a look at implementing a system to limit the amount of ammo a player has as well as a display a warning when the player has run out of ammo:

Set up the Text objects similar to how it is showed in this article.

Open the UIManager script. Add a function to update the UI based on the amount of ammo. Also add a function which will call the coroutine to show the “NO AMMO” warning on the screen:

Open the Player script and add a private int for ammo count:

In the Shoot function subtract 1 from ammo after each shot and call the UpdateAmmoUI function and pass in the amount of ammo. If ammo is less or equal to 0 call the NoAmmo function instead and then return:

Lastly, add the UI objects to the UIManager on the Inspector:

Final result:

Good luck!




Unity / C# Game developer

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

Recommended from Medium

Creating an App in Android Automotive OS

How to Lock Instagram Chats on Android

Configure multiple APKs per ABIs

Android: Call another activity when a button is pressed and close the first activity

How to make a RecyclerView in Compose — Part 2

Adventures in Launcherland: Modding the Pixel Launcher without actually changing the APK (or using…

How to Use Push Notifications With Flutter

Galaxy Shooter 2D — Stop Spawning Enemy

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
Niklas Bergstrand

Niklas Bergstrand

Unity / C# Game developer

More from Medium

So now that you’ve read the title of this blog and are interested in understanding precisely what…

I am a teacher no more

How Prostate Cancer Taught Me to Fight My Own Fires

Just Start Your Goal(Plans into Action)