- Home /
How do i fit a Guitext to a particular position for all screen resolutions?
my current gui text is at the position (0.9,0.97,0) for standalone screen res,however when i change screen res the gui text appears in a wrong place. Please help
use Screen.width and Screen.height on the rect for the first two values.
Eg: (Screen.width / 2 -25, Screen.height /2 - 25, 50, 50)
This way it takes the current screen width divide for two and then $$anonymous$$us 25 which is half the element size, same on the height. This will perfectly center your element on all resolutions.
So you have to play around with that and always consider the element size you input.
EDIT. Oh sorry, you mean to position the game object in the scne, not a gui function rect, well you can still use the above variables to calculate your Vector3. One thing, Screen.width and height are integers, so you need to cast them for the Vecto3, probably is best to do it once on Start or Awake.
i dont really understand could you please show me an example? thanks
@$$anonymous$$: GUIText objects use viewport space, not screen space, so that won't work.
Answer by aldonaletto · Sep 04, 2013 at 12:13 PM
The position of a GUIText is relative to the screen, no matter which are its dimensions: (0,0) is bottom left, (1,1) is top right, and so on. Unfortunately, in many cases this isn't sufficient to keep the text at the position you want. If the text is some kind of display info like health, status, points etc. you may get good results by setting the GUIText Anchor field properly: if the text is supposed to stay at the top-right corner (seems to be your case), select upper right anchor - this will make the text align its upper right corner to the viewport position.
But if your text is supposed to align to some scene object, it's better to use a script like ObjectLabel, a creation of our diligent colleague @Eric5h5 that makes the label follow the target object. Finally, if you want the text to keep its position and also scale according to the screen, use GUI.Label instead of GUIText and adjust the GUI matrix, as shown in this question.
Your answer
![](https://koobas.hobune.stream/wayback/20220613113540im_/https://answers.unity.com/themes/thub/images/avi.jpg)