x


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?

more ▼

asked Jul 06 '11 at 02:25 AM

RSud gravatar image

RSud
196 26 27 36

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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() );
more ▼

answered Jul 06 '11 at 02:31 AM

Molix gravatar image

Molix
4.8k 17 27 66

(comments are locked)
10|3000 characters needed characters left

thxs for the answer!!!

more ▼

answered Jul 06 '11 at 07:44 PM

RSud gravatar image

RSud
196 26 27 36

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3811
x185
x170
x34

asked: Jul 06 '11 at 02:25 AM

Seen: 1651 times

Last Updated: Jul 20 '11 at 02:41 PM