- Home /
Toggling between fullscreen, maximized window, and smaller window
I can't seem to get my game to switch to a maximized window where the window is docked to the top of the screen. I'm currently using a UI Slider to choose between these 3 options. My game is a 2D, top-down space shooter, so I want the game to not reveal any more of the level, so I have the window unable to be resized by dragging the sides, but I still want to support some screen variations. Currently I have a system to switch between Fullscreen, a 1920x1080 non-fullscreen window, and a 1024x576 window:
public void setScreenSize(float size) {
switch (size) {
case 0:
Screen.fullScreen = true;
print("FULLSCREEN");
break;
case 1:
Screen.SetResolution(1920, 1080, false);
print("MAXIMIZED WINDOW");
break;
case 2:
Screen.SetResolution(1024, 576, false);
print("WINDOWED");
break;
default:
Screen.fullScreen = true;
break;
}
}
This code works, but I'm not a fan of the 1920x1080 window as it can be moved around, part of the screen is cut off, and it doesn't match everyone's resolution. I tried to change the player's settings through UnityEditor.PlayerSettings.fullscreenMode to change it, but that didn't let me build it:
public void setScreenSize(float size) {
switch (size) {
case 0:
Screen.fullScreen = true;
print("FULLSCREEN");
break;
case 1:
UnityEditor.PlayerSettings.fullScreenMode = FullScreenMode.MaximizedWindow;
print("MAXIMIZED WINDOW");
break;
case 2:
Screen.SetResolution(1024, 576, false);
print("WINDOWED");
break;
default:
Screen.fullScreen = true;
break;
}
}
My error is: "Assets\Scripts\settingsMenu.cs(75,17): error CS0234: 'PlayerSettings' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)"
Why does UnityEditor.PlayerSettings.fullScreenMode = FullScreenMode.MaximizedWindow;
not work? Is there anyway I can maximize the window through my script? Thank you in advance.
I've also tried Screen.fullScreenMode = FullScreenMode.MaximizedWindow;
and that just glitched out a ton.
Answer by FZ_Applications · May 11, 2020 at 08:16 PM
You can't use UnityEditor in built games. The UnityEditor namespace basically only for writing editor extensions. Try this code:
Screen.SetResolution(1920, 1080, FullScreenMode.ExclusiveFullScreen, 60);
I tried this, but the window was fullscreen and not a maximized window. I tried using the other options like FullScreen$$anonymous$$ode.$$anonymous$$aximizedWindow (which doesn't make sense as to why this one doesn't work), FullScreen$$anonymous$$ode.Windowed, and FullScreen$$anonymous$$ode.FullScreenWindow, but none of them do what I wanted, either being a small window or fullscreened. Is there any other way that this can be done?
I see, FullScreen$$anonymous$$ode.$$anonymous$$aximizedWindow also doesn't work in my game.
Another approach to your problem might be to overlay black boxes over the area you want to hide and to move them with the camera.
Your answer
Follow this Question
Related Questions
Screen.SetResolution doesn't work when the game starts windowed? 0 Answers
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
Canvas not resizing when app is changed to fullscreen 1 Answer