How to make ammo appear on screen in c sharp
Hi, I am working on a game with my friend and I have made a shoot script and it works fine, it uses ammo and the ammo part works i just dont know how to make the ammo count appear on screen. I have looked for tutorials, but i only found them in javascript. I was hoping to figure out how to do this in c#. If you know of any good videos or websites that could help me do this or you know how to do this please show me, thank you. Also this is the first time i have posted a question sorry if i did it wrong
Answer by OctoMan · Oct 08, 2015 at 01:13 PM
When you use Unity 4.6 and the Canvas system, create a textfield where ever you want the count.
In your script add the namespace:
using UnityEngine.UI;
So you have access to textfields and stuff Now you create a connection to that Textfield.
public Text AmmoAmount;
Now drag the textfield in Slot in your inspector.
Finally write data into that textfield whenever you use a shot or relaod.
AmmoAmount.text = yourAmmoValue.toString();
Thats it. Cheers
Thank you so much, I have been trying to get this to work for the past week, lots of thanks.
Answer by etopsirhc · Oct 08, 2015 at 01:17 AM
add a label ui element, then in the script add a public variable of that type and drag it into the slot in the inspector. after that you just need to set variableName.text to the number you want to display.
But is the number i add constantly changing because thats what the ammo would be doing?
Your answer
![](https://koobas.hobune.stream/wayback/20220612040432im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Inter Script Communication fail 1 Answer
transform.eulerAngles not working 2 Answers
error CS0101: The namespace `global::' already contains a definition for `SceneManagerLoadScene' 0 Answers
NullReferenceException (Updated) 1 Answer
HELP I would like a button that leverage the AAA graphics 0 Answers