Fixed small issues found in playtesting
This commit is contained in:
33
Assets/Scripts/CamRatioFixer.cs
Normal file
33
Assets/Scripts/CamRatioFixer.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user