Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Dubious-Drewski · Sep 03, 2012 at 07:19 AM · guitextsimple

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dubious-Drewski · Sep 03, 2012 at 07:30 AM 0
Share

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.

avatar image AlucardJay · Sep 03, 2012 at 07:38 AM 0
Share

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() );
 }
avatar image AlucardJay · Sep 03, 2012 at 07:42 AM 0
Share

ToString() : http://docs.unity3d.com/Documentation/ScriptReference/Object.ToString.html

http://docs.unity3d.com/Documentation/ScriptReference/30_search.html?q=ToString

avatar image Dubious-Drewski · Sep 03, 2012 at 08:59 AM 0
Share

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.

avatar image AlucardJay · Sep 03, 2012 at 09:22 AM 0
Share
 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).

Show more comments
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges