Before i ask my question, i would sincerely apologize for my bad grammar.
English is not my native language:-)
My question is almost completely revealed in the Titel.
I would like to know, how i could make GUI resize and reposition according to what resolution it is played in.
I have already searched the forum, but either it was in JS or it was nothing a Newbie like me could understand.
I should also mention, that i am not an experienced Unity user, nor programmer.
My only experience is with C# and Basic Java…
so i would like if the answers wouldent be Hard-Coded, and not to complicated
Thanks
Screen.width
finds the width of a screen and Screen.height
finds height. So if you want something in the bottom right, something like this would suffice:
GUI.Button (Rect (Screen.width - x, Screen.height - y, x, y), "Button")
Where x is the width, and y is the height. If you do not subtract the x and y from the width and height, it will be offscreen, since it is the edges.
What i did with my project was to set my layout (GUITexture or normal gui buttons) on the screen by using a 1280*800 res as my goal lets say.
Then measure the actual screen size and divide by the res in which i built the scene.
Then multiply the element’s position by that ratio.
It resized and re placed everything that had that script. Tested it with various resolutions.
The code may be in JS but it should give an idea.
private var ratio:float;
private var screenHeight:float;
function Awake () {
screenHeight=Screen.height; //save screen into float.
ratio=screenHeight/800; //ratio by which to multiply to resize the buttons.
guiTexture.pixelInset.height*=ratio;
guiTexture.pixelInset.width*=ratio;
guiTexture.pixelInset.x*=ratio;
guiTexture.pixelInset.y*=ratio;
}