34 lines
685 B
C#
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
|
|
);
|
|
}
|
|
}
|
|
}
|