Ammo No Enough!- Game Dev Series 35

S.J. Jason Liu
2 min readMay 30, 2021

--

Objective: Create limited ammos & ammo counts UI.

To increase the difficulty of a shooter game, there is one option is limiting the ammo.

To limit the ammo, we will need to make some changes at shooting method and UI.

First, create an integer variable as ammo and set the default counts to 15. Under the shooting check statement, decrease it by one per each shot.

Then insides the ShootLaser() method, make it can only fire if there is still have ammo.

Next is the UI part.
Create a new ammo text gameobject in Canvas.

I used the laser sprite to make it visualize instead of word only.

Then create the variable and also a public method to update it.

To prevent some calculating error, make it only shows 0 in else statement.

Don’t forget to drag the ammo text gameobject into UIManager in Canvas.

Then we can call this method when we shoot. Back to Player script and add another line.

That’s it! You should get a limited ammo now!

--

--

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.