The Problem:
When building an in game options menu to replace Unity’s Default Resolution dialogue I noticed that while it was possible to enter fullscreen mode form windowed using:
Screen.fullscreen = true;
It was not possible to then exit fullscreen mode by setting the same value to false. I did quite a bit of googling and wasn’t really able to find anyone else who had the same problem, much less a viable solution.
But since I have since solved it I thought I’d throw up this thread in case anyone else has run into the issue so that in future it’s there should someone go looking.
How I solved it:
I was able to force unity to exit fullscreen by manually setting the resolution of the game window and changing the value of the fullscreen variable there. The code for my solution looks like this:
public void SetFullScreen(bool fullScreenValue)
{
Screen.fullScreen = fullScreenValue;
if (!fullScreenValue)
{
Resolution resolution = Screen.currentResolution;
Screen.SetResolution(resolution.width, resolution.height, fullScreenValue);
}
}
Hope this helps!