Player Ammo

Let’s add a Player Ammo display:

First, let’s create a new text box on the Canvas and adjust the settings until we’ve got it looking the way we want. Now make some changes to the UI Manager script we’ve previously attached to the Canvas.

We’re going to call the UI Manager script from the Player script and have the UI script update the score for us whenever we have a change to the ammo count. So first, we’ll create a new Serialized Field to hold the game object we want to update:

In the Unity UI let’s drag and drop that new ammo text box into our new Serialized Field.

Next, let’s add our new UpdateAmmo method to the UI Manager:

Now we can just put our calls from the Player script in place and pass in the ammo value:

And now our ammo counter will be updated when we spend or acquire ammo:

--

--

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
Richard Morgan

Richard Morgan

Unity and Flutter developer interested in creating mixed-reality applications.