이거 하나면 모바일 해상도 걱정 끝! 16:9 고정해상도 만들기
CameraResolution.cs 소스입니다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraResolution : MonoBehaviour
{
void Start()
{
Camera camera = GetComponent<Camera>();
Rect rect = camera.rect;
float scaleheight = ((float)Screen.width / Screen.height) / ((float)9 / 16); // (가로 / 세로)
float scalewidth = 1f / scaleheight;
if (scaleheight < 1)
{
rect.height = scaleheight;
rect.y = (1f - scaleheight) / 2f;
}
else
{
rect.width = scalewidth;
rect.x = (1f - scalewidth) / 2f;
}
camera.rect = rect;
}
void OnPreCull() => GL.Clear(true, true, Color.black);
}