직사각형으로 표현되는 UI요소의 경계의 왼쪽 아래가 (0, 0), 오른쪽 위가 (1, 1)
private CanvasScaler _canvasScaler;
//Awake에서 _canvasScaler = GetComponent<CanvasScaler>();
private void SetCanvasScalerMatch()
{
// Default 해상도 비율
float fixedAspectRatio = 1920f / 1080f;
// 현재 해상도 비율
float currentAspectRatio = (float)Screen.width / (float)Screen.height;
// Default 해상도보다 가로 비율이 더 긴 경우
if (currentAspectRatio > fixedAspectRatio) _canvasScaler.matchWidthOrHeight = 1;
// Default 해상도의 세로 비율이 더 길 경우
else if (currentAspectRatio < fixedAspectRatio) _canvasScaler.matchWidthOrHeight = 0;
}
이 스크립트를 사용하여 Match를 유연하게 설정할 수 있다.