Question by
Murtihere · Jun 12, 2020 at 12:12 PM ·
resolutionscreenwindowsstandalone
Unity windowed mode size is different on different screen resolutions
So I want the window size in the build to be of a certain size and it works great when displayed on 1920 x 1080 screen resolution, anything more or less than that, and the window becomes too big or too small. Is there any way for the window to be of the same window to screen size resolution?
I have used the following settings:
res.png
(39.5 kB)
Comment
Answer by DenisIsDenis · Jun 01, 2021 at 04:50 AM
If relevant, this script may help:
using UnityEngine;
public class ScreenSizer : MonoBehaviour
{
public Vector2 AspectRatio = new Vector2(16, 9); // default Aspect Ratio 16/9
public int offsetFromCorners = 100; // default offset
int width, height;
void Awake()
{
if ((int)((Screen.currentResolution.width - offsetFromCorners * 2) * AspectRatio.y / AspectRatio.x) < Screen.currentResolution.height)
{
width = (int)(Screen.currentResolution.width - offsetFromCorners * 2);
height = (int)((Screen.currentResolution.width - offsetFromCorners * 2) * AspectRatio.y / AspectRatio.x);
}
else
{
width = (int)((Screen.currentResolution.height - offsetFromCorners * 2) * AspectRatio.x / AspectRatio.y);
height = (int)(Screen.currentResolution.height - offsetFromCorners * 2);
}
Screen.SetResolution(width, height, false);
}
}