- Home /
Question by
networkZombie · May 08, 2011 at 09:40 PM ·
guipositiongameresolution
GUI messes up depending on the screen resolution
I dont know why this happens but all my GUI texts, GUI textures etc are not where they are supposed to be when I change the screen resolution to something other than my default screen resolution. How do I fix this?
Comment
Answer by Joshua · May 08, 2011 at 09:48 PM
Please use search. This has been asker and answered a LOT of times before. Basically, instead of of setting the positions with an exact number like so
Gui.Button( Rect( x, y, width, height), text);
Make it relative to the default resolution. With default I mean the one you use to design it.
var defWidth : int; var defHeight : int;
function OnGUI () {
var widthScale = Screen.width/defWidth;
var heightScale = Screen.height/defHeight;
Gui.Button( Rect( x*widthScale , y*heightScale , width*widthScale , height*heightScale ), text);
}
The scaling idea remains the same. Just apply it to scale and position or to position and pixelInset.
thank you joshua, this has been the simplest and best way to do this I've come across