- Home /
What is the correct way to programatically set the screen resolution?
I would like to allow the user to switch resolutions in the web player. I've created a script that makes the following call:
Screen.SetResolution(width, height, false);
and wired that up to an NGUI button. When I hit the button, the screen flickers, but the resolution stays the same. I know this because not only does it look the same, but I'm printing out Screen.currentResolution, and it reads 1920x1080, both before and after.
Why isn't this call working?
Update:
I just verified that the same code works when I run as a Win32 app, though it seems that Screen.currentResolution is wrong. The app changes size, but the resolution still reads 1920x1080, so currentResolution must refer to my desktop resolution. How can I print the app's actual resolution?
Answer by trs9556 · Jun 13, 2013 at 02:14 AM
If it's via the web player, why not just set the resolution of the window in your html rather than unity.
And depending on how you have your web player set up in html, that might be your problem. Unity is unable to make your resolution bigger if the html is forcing it to be a specific resolution.
I'm fine with setting the player's size in html, but that scales the player, and I need the aspect ratio to stay the same. Is there a way to do that?
$$anonymous$$y best suggestion is when you make your option to change the screen size pop up a dialog saying "Changes will take effect once restarted". Aka make the user have to restart the player for changes to take effect. That should keep your ratio.