Search Unity

Question Toggling between fullscreen, maximized window, and smaller window

Discussion in 'Editor & General Support' started by Connodore64, May 11, 2020.

  1. Connodore64

    Connodore64

    Joined:
    Feb 12, 2020
    Posts:
    10
    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:
    Code (CSharp):
    1. public void setScreenSize(float size) {
    2.         switch (size) {
    3.             case 0:
    4.                 Screen.fullScreen = true;
    5.                 print("FULLSCREEN");
    6.                 break;
    7.             case 1:
    8.                 Screen.SetResolution(1920, 1080, false);
    9.                 print("MAXIMIZED WINDOW");
    10.                 break;
    11.             case 2:
    12.                 Screen.SetResolution(1024, 576, false);
    13.                 print("WINDOWED");
    14.                 break;
    15.             default:
    16.                 Screen.fullScreen = true;
    17.                 break;
    18.         }
    19.     }
    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:
    Code (CSharp):
    1. public void setScreenSize(float size) {
    2.         switch (size) {
    3.             case 0:
    4.                 Screen.fullScreen = true;
    5.                 print("FULLSCREEN");
    6.                 break;
    7.             case 1:
    8.                 UnityEditor.PlayerSettings.fullScreenMode = FullScreenMode.MaximizedWindow;
    9.                 print("MAXIMIZED WINDOW");
    10.                 break;
    11.             case 2:
    12.                 Screen.SetResolution(1024, 576, false);
    13.                 print("WINDOWED");
    14.                 break;
    15.             default:
    16.                 Screen.fullScreen = true;
    17.                 break;
    18.         }
    19.     }
    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.