- Home /
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:
They insist on having a box drawn around my text. I don't want that.
I can't seem to get them to print a variable value, rather than a static string
Any help?
Answer by AlucardJay · Sep 03, 2012 at 07:21 AM
Consider finding a GUI tutorial, or read all the available options from the API (Unity Scripting Reference) : http://docs.unity3d.com/Documentation/ScriptReference/GUI.html
GUI Basics (follow this!) : http://docs.unity3d.com/Documentation/Components/gui-Basics.html
GUI scripting guide (follow this!) : http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html
Display text : http://docs.unity3d.com/Documentation/ScriptReference/GUI.Label.html
Input field : http://docs.unity3d.com/Documentation/ScriptReference/GUI.TextField.html
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.
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() );
}
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.
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).
Answer by Dino-Dini · Jun 08, 2013 at 01:57 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613080543im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Move the text in a GUI Button/Box 1 Answer
GUI.label overlapping text 1 Answer
Gui Text Script 4 Answers
Alpha not working in GUITex 0 Answers
Intro GUI Text Script... 3 Answers