- Home /
How to display Int variable onto the GUI/HUD
I'm trying to make a health and armor system and I want it to be displayed onto the HUD for obvious reasons. I've looked at other similar topics, but none of them helped me, some of them just confused me. Here is what I have so far from what I gathered from other topics using C#:
using UnityEngine; using System.Collections; public class PlayerHealth : MonoBehaviour { int myHealth = 100; void Update() { GUI.Text = myHealth.ToString(); } }
That sample seemed to work for others but for me it gives me the error: "UnityEngine.GUI" does not contain a definition for "Text"
Please help! I don't have too much experience with coding obviously, or with Unity.
You need to research the differences between the three built-in types of text:
GUI.Label() which can only be executed in OnGUI().
GUIText - always appears on top
3D Text/Text $$anonymous$$esh - in the 3D environment but by default always in front.
If the above script is on a GUIText game object, a line to set it is:
guiText.text = myHealth.ToString();