Files
Inter-Face-Off/Assets/Scripts/CamRatioFixer.cs
2026-01-29 13:54:10 +00:00

34 lines
685 B
C#

using UnityEngine;
public class CamRatioFixer : MonoBehaviour
{
public Camera cam;
void Update()
{
float targetAspect = 16f / 9f;
float windowAspect = (float)Screen.width / Screen.height;
float scale = windowAspect / targetAspect;
if (scale < 1f)
{
cam.rect = new Rect(
0,
(1f - scale) / 2f,
1f,
scale
);
}
else
{
float width = 1f / scale;
cam.rect = new Rect(
(1f - width) / 2f,
0,
width,
1f
);
}
}
}