How to output a variable in a

function OnGUI () {
// Make a background box
GUI.Box (Rect (10,10,100,90), “Hello”);

The above works. But I want to do the following, with a real variable of course…

function OnGUI () {
var x : float;
x = 22.2;
GUI.Box (Rect (10,10,100,90), x);

the above fails compile.
all the code samples I see just output a string. what is the syntax if I want to output a variable?

The GUI functions expect a string or GUIContent to draw (rather than a float). In your case, the simplest thing would be to just use ToString(). e.g.

GUI.Box( Rect(10,10,100,90), x.ToString() );

thxs for the answer!!!