- Home /
How to output a variable in a GUI.box?
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?
Answer by Molix · Jul 06, 2011 at 02:31 AM
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() );
Your answer
Follow this Question
Related Questions
GUIBox fontSize without changing other labels? 3 Answers
full screen wide GUI.Box 3 Answers
Editing certain words in a single NGUI Text Box 0 Answers
GUI.DrawTexture Error & Static Variables!! 2 Answers
OnGUI using UnityEditor how to make FloatField work? 1 Answer