- Home /
Transform on GUIText not working?
I'm trying to make a GUIText appear in the center of the screen. Most answers in this forum involve changing the transform. However, that doesn't seem to affect the object position at all. Technically, I can set the pixel offset to center the object on startup (using this answer), but I'd really like to make transform work. Any ideas?
EDIT:
Changing the transform to 0.5, 0.5 works in one scene, but doesn't work in others (even though they're operational). So the problem is not with the technique, but some setup detail of the scene, I just can't figure out which.
The transform position of X .5 and Y .5 puts it in the center of the screen, changing X to .1 moves it left, etc; that does not move it for you?
No - changing the transform to any value whatsoever seems to have no effect. And I double-checked the code to make sure it's not set programmatically.
When you press Play, what Pos does your GUItext show up at?
It actually doesn't. Which is most strange. EDIT: perhaps the GUILayer is turned off somehow? At least one other person reported this. But it is turned on in the scene's Inspector.
Answer by whydoidoit · Aug 22, 2013 at 07:33 AM
GUIText does not use world positions in the Transform at all for it's in game positioning (it wouldn't make sense in terms of GUI position). If you want text with a world position you need to use a TextMesh instead.
Or position your GUIText's position at the result of a Camera.WorldToViewportPoint call given a world position.
Not sure if we might be crossing wires on this? I added a new GUIText gameobject to sample project @ Unity puts it at x.5 and y.5 and it's in the middle of the screen. Changing the X and Y moves it as one would imagine in screen terms.
I need to center the GUIText on the viewport, not the world.
Answer by robertbu · Aug 22, 2013 at 07:35 AM
GUIText lives in Viewport space. Viewport space goes from (0,0) in the lower left corner to (1,1) in the upper right corner. As @getyour411 suggests, to put the GUIText in the center of the screen using the transform, the position in the transform must be set to (0.5, 0.5). If you are using the transform to center the text, the Pixel Offset should be set to (0,0).
This works in one scene, but not others, please see my edit.
Answer by BMF · Feb 12, 2014 at 04:10 PM
I just find myself struggling with GUIText too. I was trying to call this
protected GUIText displayText; displayText = transform.Find("W/Ethename").guiText;
which was returning NULL, of course. In fact, It seems you can't access it like that.
GUIText lives in Viewport space.
^This. GUIText does not have a NORMAL transform that you can access. A solution is to use the GameObject.Find()
method instead.
Your answer
Follow this Question
Related Questions
How to set the position of a guitext using transform? 1 Answer
Line render from an object to a click 0 Answers
Teleporting Player to a point using box colliders 1 Answer
positioning gui! 2 Answers
transform.position on basis of rotation 0 Answers