Using a variable as text

Hi everyone, I have an issue with my GUI text. I am able to add a set text on it. For example i can make the words “Hello World” appear on my screen. But lets say i have a variable. For example, X=“Hello World”. How do I add the variable as text.
#pragma strict

var Health = 100;

function OnGUI(){



I have tried this and it doesn’t work. The error i get is…

No appropriate version of “UnityEngine.GUI.Label” for the argument list ‘(UnityEngine.Rect,int)’ was found

use ToString() to typecast your int as a string

GUI.Label(Rect(0,0,Screen.width,Screen.height), Health.ToString() );

in future, please format your code

Use a formatted string to add the integer.


ToString() will only work with non-primitive types that derive from Object.