I have a canvas that is set to Screen Space - Camera and Scale With Screen Size and it works fine for when the app is in Windowed mode. But when i make it full screen using Screen.fullScreen = true
, the canvas stays at the same aspect ratio it was when it was windowed. How can I fix it?
On your canvas under canvas scaling. You can select your canvas scaling mode. You have to set it to scale with screen size. Depending on whether it’s a vertical or horizontal game. You can adjust the slider. This affects how much each direction is scaled.
Didn’t solve it for me, (on 2021.2.19f1)
This code worked for me:
Vector2Int rez;
public void ToggleFullScreen()
{
FullScreenMode mode;
if (Screen.fullScreenMode == FullScreenMode.Windowed)
{
//Save the windowed size
rez.y = Screen.height;
rez.x = Screen.width;
//
mode = FullScreenMode.FullScreenWindow;
Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, mode); //This is the important part!
}
else
{
mode = FullScreenMode.Windowed;
Screen.SetResolution(rez.x, rez.y, mode);
}
}