- Home /
GUIText multi-platform and multi-resolution position
Hello,
I am having trouble with the GUIText object. I want to have it as a "Score" label in the upper-right corner of the screen. The problem is, the "alignment" and "anchor" props dont really alter the positioin that much, so I tried with pixel offset.. but that kinda depends on the resolution the player chooses dosn't it?
Is there a good way to position a GUIText so that it is always in the upper-right corner of the screen, independent on platform and resolution?
Answer by ByteSheep · Jan 12, 2012 at 05:40 PM
There are plenty of resources and asked questions concerning GUI elements etc, here's a similar thread. You can use Screen.Width and Screen.Height or just set it using a number between -1 and 1 for x and y..
Im not sure what X and Y values we are talking about here. Its not the pixel offset right?
It's the screen position of the texture or text- If x and y are both set to 0 then your texture will appear in the top-left corner. If x and y are set to 1 then it will be in the bottom-right corner. I think that's it, might be -1 is left and 0 is middle but not sure.. Either way I guess you get the principal. It's fairly simple to do what you want, here's a good documentary of the unity GUI: http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html Ps: The x and y values are set when drawing the texture in the OnGUI function of a script. Are you currently using a script to position your GUI?
var myTexture : Texture2D; var myTextureHeight : float; var myTextureWidth : float;
function OnGUI(){
GUI.drawTexture(Rect( Screen.width * 0.5, Screen.height * 0.5, myTextureWidth, myTextureHeight), myTexture);
}
Sorry the format is weird but you could try this.. You will have to set myTextureHeight/width to the height and width of your texture, then drag your text to the myTexture variable in the inspector.
Yes, or you can use it to display a normal texture. There are two types of text in unity I believe, one that can be viewed in 3d space and one that cannot.. In your case it would perhaps be best to use the later, unless your text is meant to be an object in the scene.
Your answer
Follow this Question
Related Questions
Network - Client still in Network.Connections after disconnect 2 Answers
problem with gui??? 0 Answers
Question about Network and NetworkViewID 1 Answer
PC-only assets? 0 Answers