If you’ve ever played a game with shooting weapons, you’ve probably encountered limited Ammo. It adds further challenge for the player, which adds fun for some players.

Today I’m gonna show you how I scripted a very simple ammo limit and tracking UI.

The new Variables in my player script:

I tweaked my FireLaser method:

--

--

Those of you who chose Fullscreen might now be cursing my name because I didn’t warn you there wouldn’t be any way to quit the game without resorting to Task Manager violence.

What can I say? Unity only does what we tell it to. So how do we get ourselves out of our game when we are ready to quit? By telling Unity that the escape key = quit.

It’s really easy! Open up your GameManager script and scroll down to private void Update(). Typing this will tell Unity that if the Esc key (KeyCode.Escape) is pushed (Input.GetKeyDown), the game will close entirely (Application.Quit).

That’s all there is to it! Save and then make another build. Make sure to update that version number.

See you next time!

Shyla

--

--