- Home /
Randomly floating GUI Texture
I have an object (Object A) with a GUITexture attached to it. When I make Object A a child of Object B which is a child of my Main Camera, it causes the GUITexture of Object A to float around randomly in front of my camera when I move my mouse or just my character around the center of my map. Any help?
Answer by Owen-Reynolds · May 11, 2013 at 10:40 PM
GUITextures can't be children of non-GUI objects (they can, but it makes the mess you're seeing.) If you want some text sticks to you "in the world" can either use a Text3D, or look up the Camera.WorldToScreenPoint
trick for positioning a GUITexture.
The problem is, GUITextures use different 0-1 screen coords. If you child it to a ball, and the ball moves +1 x in the world (which is probably a small amount on the screen,) the automatic child-mover incorrectly moves the GUITexture child by +1 x screens, which pushes it completely off the edge of the 0-1 screen world.
Why am I even seeing the GUITexture at all though? I don't have any code telling it to draw it on the screen, unless it automatically draws it every frame? That part doesn't really make sense to me. What you are saying however does make sense, I just don't understand why the game is randomly trying to draw the texture in screen space in the first place without me telling it to. I thought that the GUITexture was a sort of placeholder for a graphic that you have to manually code in when and where it is drawn.
I've converted your "answer" into a question. Answers are reserved for attempts to answer your question. Putting comments as answers runs up the count of answers for a question and therefore reduces the chance for additional people will give you an answer.
As for your comment, GUITextures are very different from GUI.DrawTexture(). As @Owen Reynolds mentioned, GUITextures live in Viewport coordinates. And they don't require a code statement each from to draw. They start at (0,0) in the lower left corner, and end at (1,1) in the upper right. GUI.DrawTexture uses GUI coordinates which start in the upper right and have the same resolution as your game. And they do require that you have a code statement that draws them each frame. Both are different than world coordinates where game objects live.
If you switch to Game view (not playing, just click the Game tab,) you can see GUIText's and GUITexture's as you make them, and can visually position them on the screen.
But, if you drag next to the xy position vars, you sort of get the same oddness -- it moves them really fast since it doesn't "know" that only 0-1 are on screen.
You can use them as texture placeholders, and can dynamically move them around, if you like (many of $$anonymous$$e start offscreen at 999/999.)
Your answer
![](https://koobas.hobune.stream/wayback/20220613102032im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to GUI texture image change? 1 Answer
Gui Texture GameObject not showing up 1 Answer
rotating GUI texture by angle 2 Answers
Sprites and minmizing memory usage 1 Answer
How to place/add a HD image/picture in background of my game? 0 Answers