- UI 배치는 세로 해상도 기준으로 하기(Match Width, 0에 가깝게 둔 상태로)
- Canvas Scaler의 Reference Resolution이 넘어가는 비율로, 가로가 더 넓어지면 Height에 가깝게 MatchWidthOrHeight를 1로 바꿔주도록 Canvas Scaler 달린 컴포넌트에 아래의 스크립트 달아주기
using UnityEngine;
using UnityEngine.UI;
[ExecuteInEditMode]
[RequireComponent(typeof(CanvasScaler))]
public class CanvasScalerController : MonoBehaviour
{
private CanvasScaler scaler;
private float referenceRatio;
private void Awake()
{
scaler = GetComponent<CanvasScaler>();
UpdateMatchWithOrHeight();
}
#if UNITY_EDITOR
private void Update()
{
UpdateMatchWithOrHeight();
}
private void UpdateMatchWithOrHeight()
{
referenceRatio = scaler.referenceResolution.x / scaler.referenceResolution.y;
if(referenceRatio < Camera.main.aspect)
{
scaler.matchWidthOrHeight = 1;
}
else
{
scaler.matchWidthOrHeight = 0;
}
}
#endif
}
'Unity' 카테고리의 다른 글
마우스 이벤트 감지 I~Handler 인터페이스들 (0) | 2023.07.11 |
---|---|
TMP SubMeshUI가 자꾸 생성될 때 (0) | 2023.05.23 |
버튼이 동작하지 않을 때 Graphic Raycaster 확인하기 (0) | 2023.02.14 |
Time.timeScale로 일시정지했다면 고려할 점 (0) | 2023.01.09 |
코루틴 실행 중인지 체크하기 (0) | 2022.12.31 |
댓글