x


How to draw bare GUI text with no box border

This HAS to have a simple answer, yet I cannot find any info on this. All I want to do is draw bare text on to the GUI so I can do some debugging. I just want simple, like they used to do it in BASIC:

Print bulletSpeed, 10, 20

All I can find are things like GUI.label and GUI.box, which don't work for two reasons:

  1. They insist on having a box drawn around my text. I don't want that.
  2. I can't seem to get them to print a variable value, rather than a static string

Any help?

more ▼

asked Sep 03, 2012 at 07:19 AM

Dubious Drewski gravatar image

Dubious Drewski
139 21 368 40

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

2 answers: sort voted first
more ▼

answered Sep 03, 2012 at 07:21 AM

alucardj gravatar image

alucardj
29.5k 167 1049 215

I've gone through those, and they do not solve my problem. Here is the kind of example they give:

function OnGUI () { GUI.Label (Rect (10, 10, 100, 20), "Hello World!"); }

That draws a Rect and I do not want that. And it doesn't allow me to draw a realtime variable, only strings. I can't find any examples that don't operate like this. This isn't the solution I need.

You took all that time to write that answer for me (Thank you), but it was in vain, because all you really had to do was type one line of code, and I would have become enlightened.

What single line of code will allow me to print a variable to the gui? That's all I am aching to learn.

Sep 03, 2012 at 07:30 AM Dubious Drewski

I believe the one link : http://docs.unity3d.com/Documentation/ScriptReference/GUI.html : gives all the info you need. Every command is covered there.

The answer to your question I have also linked : http://docs.unity3d.com/Documentation/ScriptReference/GUI.TextField.html

THis is how to add an input field for the user to type in. Direct copy :

 var stringToEdit : String = "Hello World";
 function OnGUI () {
     stringToEdit = GUI.TextField (Rect (10, 10, 200, 20), stringToEdit, 25);
 }

and to confirm what you type is inputted, add :

 function Update () {
     Debug.Log( "stringToEdit = " + stringToEdit  );
 }

To display a variable that is NOT a string, you can use this (http://docs.unity3d.com/Documentation/ScriptReference/GUI.Label.html) :

 var myVariable : float = 1.25;
 function OnGUI () {
     GUI.Label(Rect (10, 10, 200, 20), myVariable.ToString() );
 }
Sep 03, 2012 at 07:38 AM alucardj

The .ToString function solved the most pressing problem I was facing, and I thank you very much for that.

But half of my question remains unanswered, and so I must ask it again: How do I draw text WITHOUT having to draw a silly Rect behind the text?

Please remember, the answer to my original question is probably nothing more than a single line of code, and that's all I'm requesting.

All I'm asking is this: What is the unity equivelent of the QBASIC code:

Print variable, 10, 20

Just that.

Sep 03, 2012 at 08:59 AM Dubious Drewski
 var myVariable : float = 1.25;
 function OnGUI () {
     GUI.Label(Rect (10, 10, 200, 20), myVariable.ToString() );
 }

Create a new scene, create a new script and place this in the script. Now attach the script to the camera (or empty gameObject) then press play. In the Inspector, change the value in myVariable. This change should reflect in the GUI display in the scene. This is tested and working. And with No Bounding Rectangle.

Regarding Rect, this is just the way to define the area in which the GUI.Label is displayed. You cannot simply state a position x and y. Rect is basically saying display my GUI from (posX, PosY, width, height). SO there is no way around it, you just have to work with it. Just set a standard i.e. Rect( startPosX, startPosY, width, height) e.g. Rect( 10, 10, 200, 25 )

You can see how rect affects the display. Try this script :

 var myString : String = "qwertyuiopasdfghjkl";
 function OnGUI () {
     GUI.Label(Rect (10, 10, 10, 25), myString );
 }

you will note that the characters outside the rect are not displayed. This is how GUI works =]

The GUI is not perfect, and this is reflected by the fact that there are many GUI alternatives for Unity : Vectrocity, FlyingText3D, UIToolkit, NGUI, etc (I use my own GUI that I wrote myself).

Sep 03, 2012 at 09:22 AM alucardj
(comments are locked)
10|3000 characters needed characters left

This actually answers the question:

http://answers.unity3d.com/questions/159920/textfield-with-invisible-text-box.html

Text = GUI.TextField (Rect(200,200,200,200),Text, 1024,"Label");

The last argument is the style which can be specified by name.

more ▼

answered Jun 08, 2013 at 01:57 PM

Dino Dini gravatar image

Dino Dini
1

(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:

x6006
x934
x176

asked: Sep 03, 2012 at 07:19 AM

Seen: 10845 times

Last Updated: Jun 08, 2013 at 01:57 PM