Fullscreen to Windowed and back again [Solved]

I have a dropdown with two options, fullscreen and windowed. Using the two lines I’ve commented out it works just fine, but the windowed mode is the size of the whole screen and part of it is under the windows taskbar. I want to eliminate this problem. When windowed mode is chosen it should display a window that’s half the size of the players monitor.

What I have written below is what I think should do this, and it does, but it has problems. Going from fullscreen to windowed works fine, but going from windowed to fullscreen makes the game fullscreen again but leaves the lower resolution so everything goes blurry. Also, if I switch to windowed mode and exit the game and then run it again and it pulls from playerprefs that windowed mode should be running, but with each additional opening of the game it cuts the window size in half again so that eventually running the game produces a little tiny window.

What am I doing wrong here?

    public void SetScreenMode () {

        if (screenModeDropdown.value == 0) {
            //Screen.fullScreen = true;
            Screen.SetResolution (Screen.width, Screen.height, true);
        }
        else if (screenModeDropdown.value == 1) {
            //Screen.fullScreen = false;
            Screen.SetResolution (Screen.width / 2, Screen.height / 2, false);
        }

        PlayerPrefs.SetInt ("ScreenMode", screenModeDropdown.value);

    }

I did something similar in this way:

  1. In the Awake function I store the Screen.currentResolution.width and Screen.currentResolution.height as ‘FullScreenWidth/Height’ - that way I’ve always got a copy of it for switching later on

  2. When I switch to fullscreen I do this: (using the previously stored values)
    Screen.SetResolution( m_FullScreenWidth , m_FullScreenHeight , true );

  3. When I switch to windowed I do this:
    Screen.SetResolution( 1136 , 640 , false );
    (this can use half of the fullscreen width/height if you prefer)

1 Like

That’s actually what I ended up doing, I was just about to report the issue solved when I saw you replied. Thanks!

1 Like