Skip to main content
Source Link

Many thanks to the DMGregory for help in this matter

The problem was that I have a script which manipulate with camera.rect:

using UnityEngine;

public class GameAspectRatio : MonoBehaviour {
    [SerializeField] private new Camera camera;
    [SerializeField] private float targetAspect;

    private void Awake() {
        // determine the game window's current aspect ratio
        float windowAspect = (float) Screen.width / (float) Screen.height;

        // current viewport height should be scaled by this amount
        float scaleHeight = windowAspect / targetAspect;
        float scaleWidth = 1.0f / scaleHeight;

        camera.rect = scaleHeight < 1.0f ?
            //adding letterboxes
            new Rect(0, (1.0f - scaleHeight) / 2.0f, 1, scaleHeight) :
            //adding pillarboxes
            new Rect((1.0f - scaleWidth) / 2.0f, 0, scaleWidth, 1);
    }
}

After this advice I edited my script to this:

using UnityEngine;

public class GameAspectRatio : MonoBehaviour {
    [SerializeField] private new Camera camera;
    [SerializeField] private float targetAspect;

    private void Awake() {
        // determine the game window's current aspect ratio
        float windowAspect = (float) Screen.width / (float) Screen.height;

        // current viewport height should be scaled by this amount
        float scaleHeight = windowAspect / targetAspect;
        float scaleWidth = 1.0f / scaleHeight;

        if (scaleHeight < 1.0f) {
            //adding letterboxes
            camera.rect = new Rect(0, (1.0f - scaleHeight) / 2.0f, 1, scaleHeight);
        }
    }
}

And now everything is working fine:

enter image description here

Post Made Community Wiki by EzioMercer