반응형
- 코드 작성
using UnityEngine;
using UnityEngine.UI;
public class UIOverlapChecker : MonoBehaviour
{
public RectTransform rectTransform1;
public RectTransform rectTransform2;
private Rect rect1;
private Rect rect2;
void Update()
{
rect1 = new Rect(rectTransform1.position.x - rectTransform1.rect.width / 2,
rectTransform1.position.y - rectTransform1.rect.height / 2,
rectTransform1.rect.width, rectTransform1.rect.height);
rect2 = new Rect(rectTransform2.position.x - rectTransform2.rect.width / 2,
rectTransform2.position.y - rectTransform2.rect.height / 2,
rectTransform2.rect.width, rectTransform2.rect.height);
if (rect1.Overlaps(rect2))
{
Debug.Log("UI가 겹쳤습니다.");
}
else
{
Debug.Log("UI가 겹치지 않았습니다.");
}
}
}
반응형