- Home /
Lock Resolution
Is it possible to lock a game at a set resolution and prevent the user from resizing the window or switching fullscreen? Fullscreen wouldn't be a problem except that if you switch to fullscreen and back, Mac OS X retains the monitor's native resolution in the new window size regardless of its size prior to fullscreen.
Another solution might be to allow fullscreen, but return the window to the preferred size on minimizingthis would require an onFullscreen()
callback (or something like it).
Much help would be appreciated!
Answer by Rennat · Dec 02, 2010 at 05:14 AM
Screen.fullScreen
is a bool
property that can be read or set. You can use this to determine if the player has just left fullscreen and switch to a different resolution.
example:
private var wasFullScreen : Boolean = false;
function Update () { if (wasFullScreen && !Screen.fullScreen) { // this gets executed once right after leaving full screen } if (!wasFullScreen && Screen.fullScreen) { // this gets executed once right after entering full screen } wasFullScreen = Screen.fullScreen; }
edit:
If you're building for the web player you can disable the right click menu so people can't go fullscreen to begin with.
To get to the setting go to File > Build Settings, then choose Player Settings and select No Context Menu for the Web Player Template.
Excellent, I wondered if it could be used that way. Thank you!
Ideally, it would be better if I could completely disable fullscreen and resolution changes, but this serves as a workable substitute.
well you could test for fullscreen every frame and set it to false if if ever goes fullscreen :D or if you're using a web player there is a setting to hide the context (right click) menu so there is no option to go fullscreen.
That's what I ended up doingit does prevent fullscreen, but there is an unfortunate momentary "blink". And it is counter-intuitive: having the option implies that the user can do it, and preventing its execution is more frustrating than not giving the user the option. $$anonymous$$aybe an item for the Unity wish list...
Your answer
![](https://koobas.hobune.stream/wayback/20220613085342im_/https://answers.unity.com/themes/thub/images/avi.jpg)