- Home /
auto detect resolution
is there a way to make my script recognize on what is the resolution of the pc i am using.. for example I change the resolution on the .exe, the one you select before starting the game, the script will automatically adjust all the gui based on the resolution you selected
Answer by perchik · Feb 01, 2012 at 06:42 PM
Well you can use Screen.currentResolution to get a Resolution object so you can do Screen.currentResolution.width, or height if you want specific stuff. Alternatively you can get the screen height and width directly. Whenever I draw GUIs I always base my dimensions on screen height and with. In C# it's literally Screen.width or Screen.height
Here's a real basic example
GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),GUI.skin.FindStyle("Background").normal.background);
so, if i use Screen.currentResolution , the GUI will adjust automatically when you select different resolution?
As far as I know, all the Screen. variables are measured on every Update() call. I've never used Screen.currentResolution, but I know that using Screen.width and Screen.height updates every frame. So provided you draw your gui elements with something baed on one of those, the gui will scale as the window is changed. If you want to play with it, just draw a GUI.Box with the width as Screen.width/2 and the height as Screen.height/2 and then run it. When you drag the window, the box will always be one half of the screen height and one half of the width.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Not every Class in the API is derived from the "Object"-Class, so what are they? 2 Answers
Script to teleport player (Beginner here) 0 Answers
How to learn scripting without Unity 3 Answers
How to smooth between values? 2 Answers