What the hell is going on?

Hi,
I just want to know why the text position changes by game resolution? For example I write following code

GUI.Label (Rect (166, 166, 410, 70), “My Name Is Ashly”);

So now in the game the text position will changes at different resolutions :face_with_spiral_eyes:

If somebody playing the game on (1280 * 1024) R the text position would be different with (800 * 600)
Why it’s like that?

It’s in the FAQ. The short of it is your telling your computer to place your text at a certain coordinate on your screen, however if your screen changes size the location of that coordinate changes. When your working on a GUI you need to work with percentages instead of exact numbers. You may also want to choose a more descriptive title for your post, it aids other peoples searches.

FAQ
http://forum.unity3d.com/threads/19302-Scripting-Section-FAQ

Thank you, But how can I’ll change the GUI.Label position to show it at a certain place?

Your going to have to use a little bit of math to get it exactly where you want it. Your going to want to start by getting the screens width/height then dividing it by however far you want it over before subtracting half your texts width. It sounds a lot more complicated then it actually is, (((screenwidth/screensegments)*segmentsover)-(textwidth/2)) for example would place it in the middle of your screen width wise.

Instead of OnGUI code, you might prefer to use a GUIText object, which uses normalized viewport coordinates, so it’s always positioned the same regardless of resolution. Also, if you uncheck “pixel correct” and use the x/y scale values instead, then it will always be the same size regardless of resolution.

–Eric

Thanks guys, it’s solved

Thanks a lot, It was so useful. I just have one more problem
I use a GUIText and attached that to main camera but when I’ve rotate the camera the text get vanished :smile:

When you attach something to another object it becomes a child of that object and inherits any changes(I think it’s all, may want to check) made to it including transform adjustments. It’s relocating the GUI text every time you move your camera, all you need to do is detach it and the GUI text will automatically stay on the screen.

I do that too but still when I rotate and attach camera to an object I lose Text, For example I have a camera and when I play the game I’m able to see text and everything is good but when I rotate and attach camera to an object I loss text

No one had this problem before?

Solved, thanks for help