- Home /
GUI Aspect Ratio?
Hiya guys, I was just wondering something. I have several GUI Textures in my scene and I noticed that whenever I run my build in different aspect ratios they disappear due to being cut off the side.
How do I make it so that they stay in the same place regardless of screen size?
Example of my code below:
function OnGUI ()
{
GUI.Label (Rect (200, 800, 200, 100), "Bullets Remaining: " +BulletsLeft, customGuiStyle);
GUI.Label (Rect (200, 840, 200, 40), "Clips Remaining: " +Clips, customGuiStyle);
}
Answer by Tim-Michels · Oct 29, 2012 at 12:39 PM
You should use Screen.width and Screen.height as values for the calculation of your position.
If you want to "dock" an element to a certain position, you could do something like this:
GUI.Label (Rect (Screen.width*0.2f, Screen.height*0.2f, 200, 100), "Bullets Remaining: " +BulletsLeft, customGuiStyle);
You can also use the that calculation to scale your label accordingly. Hope this helps ;)
Your answer
Follow this Question
Related Questions
Resolution & aspect ratio GUI 1 Answer
How I can stretch texture with GUI.DrawTextureWithTexCoords ? 1 Answer
Assets size changed 1 Answer
Resizing GUI position with screen size? 0 Answers
GUI Texture Control Problem !!!!! 1 Answer