The Maximum Ammo Amount Limit- Game Dev Series 41

S.J. Jason Liu
2 min readJun 5, 2021

Objective: Create a maximum ammo limit to Player.

Set a maximum limit to ammo is quite fair to game design. You either give the player a few ammo, or set a max limit to them. As this kind of space shooter game, an ammo maximum limit would be reasonable.

To set a maximum ammo limit, we will need to adjust Player and UIManager these 2 scripts.

Player

Create another integer variable to storage maximum ammo with SerializeField. This would make it easier if we want to change the number of maximum later.

In the Update() method, add _laserMaxCounts variable to UpdateAmmo(). We will make the UI display these 2 number at the same time.

Then go to AmmoCollected() method. Create another if statement to prevent the ammo is added over the maximum limit.
And also update the UI again at the bottom.

That should be done with Player script.

UIManager

With UI is quite easy. In the UpdateAmmo() method, add another integer that it will receive from Player script.

Then we can just update the UI with these 2 integers.

Now you have the maximum ammo limit!

--

--

S.J. Jason Liu

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