x


How the GUItext works ?

Hey there,

I don't understand how the GUItext thing is working. I have a new project with a GUItext assigned to a simple GameObject. The GUItext has some text but nothing is rendering on the screen.

I found some related topics but nothing specific enough.

I worked with GUI.Label() but it seems that the logic is different ? (you have to assigned the GUItext to an object)

Thx

more ▼

asked Feb 15, 2010 at 10:55 PM

Legogo gravatar image

Legogo
88 8 8 16

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

2 answers: sort voted first

The two things you mention there are as far as I know not really related. For the GUIText you simply go to your scene and GameObject->Create Other->GUIText. This will create a GUI game object in your scene which is rendered.

The GUI.Label is something that you would place in a script. You create a JS script and put the folling in tehre (from the documentation):

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

This will create a label displaying "Hello World!" at the specified position. So the one option is a game object, the other option is via scripting.

more ▼

answered Feb 16, 2010 at 12:21 AM

Sebas gravatar image

Sebas
4.8k 21 24 56

The for the replies ! That almost answer my question : The thing is that you can assigned a "GUIText" to an object (select object > Component > Rendering > GUIText). This is a different approach. So : what's the difference between the GUIText from the GameObject menu and the one you stick to an existing object ? (one work and the other don't)

Thx

Feb 16, 2010 at 11:55 AM Legogo

it is essentially the same thing. Both are actually gameObjects with the GUIText Component attached. If you create it the way I described above, it creates a GameObject called GUIText and adds the GUIText Component. As Eric mentioned below, it must be in viewport space, so just try giving it X and Y of 0.5 to render it in the middle of the screen. That should work.

Feb 16, 2010 at 08:05 PM Sebas

It could be important to note that the placement of the label also is rotated from gui rotate functions. I experienced a major issue when trying to use .Label, as the position was rotated to an off screen position. Keep this in mind ^^

Oct 24, 2012 at 01:05 PM Sonaten
(comments are locked)
10|3000 characters needed characters left

GUIText objects use viewport space, so they must be in the range of 0..1 in order to be visible. Also the camera must have a GUILayer component.

more ▼

answered Feb 16, 2010 at 03:44 AM

Eric5h5 gravatar image

Eric5h5
110k 55 181 659

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

x5794

asked: Feb 15, 2010 at 10:55 PM

Seen: 27097 times

Last Updated: Oct 24, 2012 at 01:05 PM