Search code examples
windowsunity-game-engineresolution

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:

My build settings


Solution

  • Afaik you can set the resolution depending on the Display screen size using Screen.currentResolution and Screen.SetResolution somewhat like e.g.

    public class ScreenSizeController : MonoBehaviour
    {
        // how much space (percentage) of the screen should your window fill
        [Range(0f,1f)]
        public float fillX;
        [Range(0f,1f)]
        public float fillY;
    
        private void Awake()
        {
            // Get actual display resolution
            var res = Screen.currentResolution;
    
            // calculate target resolution using the fill
            var targetX = fillX * res.width;
            var targetY = fillY * res.height;
    
            // Set player resolution
            Screen.SetResolution(targetX, targetY, false);
        }
    }
    

    Note: Typed on smartphone but I hope the idea gets clear