- Home /
Question by
andrew-furlyk · Apr 07, 2015 at 12:40 AM ·
guivariableintlabel
i cant make a label show my var Health : int = 100;
said in the title i cant make my GUI label show my int in it here is the code #pragma strict var LabelBool : boolean = false; var InfoMenu : boolean = false; var Health : int = 100;
function OnGUI ()
{ if ( LabelBool )
{
GUI.Label (Rect (0,0,50,50),"Press E");
}
if ( InfoMenu )
{
GUI.Label (Rect (0,0,75,50), "Health " Health);
GUI.Box (Rect (0,0,250,350),"Player Info");
}
}
function Start ()
{
Debug.Log ( Health );
}
function Update ()
{
if ( Health )
{
Health = 80;
}
if (Input.GetKeyDown (KeyCode.E))
{
InfoMenu = !InfoMenu;
}
}
function OnTriggerEnter (other : Collider)
{
LabelBool = true;
}
function OnTriggerExit(other)
{
InfoMenu = false;
LabelBool = false;
}
function OnTriggerStay(other)
{
if ( LabelBool == true && InfoMenu == true )
{
LabelBool = false;
}
if ( LabelBool == false && InfoMenu == false )
{
LabelBool = true;
}
}
Comment
Answer by winsjansen · Apr 07, 2015 at 11:25 AM
I've never used JS but I'm pretty sure you can get it to work by just changing;
GUI.Label (Rect (0,0,75,50), "Health " Health);
Into;
GUI.Label (Rect (0,0,75,50), "Health " + Health);
Usually if you want to add multiple variables to a string like this you have to add + for each variable. Here you are trying to add the string variable "Health", and after that adding the integer variable named "Health", without using + the game don't know what you are trying to do here.
At least thats how it goes for C# that is, try it ;)
thanks i will see if i have any problems and if it works.