Ammo No Enough!- Game Dev Series 35

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!

--

--

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
S.J. Jason Liu

S.J. Jason Liu

99 Followers

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