Create a Visual Ammo Counter in Unity

Mike Brisson
2 min readApr 27, 2021

For my 2D game, I decided against a numerical counter and opted for a more visually pleasing one.

In order to start this, I created an empty array of bullet images with a size of [_maxAmmo]. I then instantiated the array and added each newly created image to the array:

Here I’m using a predefined offset to ensure the images don’t overlap and multiplying that offset with a counter to keep them uniform. After this we have a complete array with our images. If you want to limit the number across you can introduce a couple new variables:

As for removing the images after you have fired, I added a callback method from my player script:

I’m using a cooldown so I needed to pass that into my Action

Back in my UIManager is where I implement the callback:

Here I’m checking if the image in the array is already deactivated; if it is, move to the next one. If it is active, deactivate it and break out of the loop.

You can do a few things to add to the effect like I have with an IEnumerator and animations.

--

--