"If you do nothing, nothing will happen."

프로그래밍

[Unity] UGUI 에서 터치 좌표에 UI가 있는지 판별하기

tedhong 2023. 2. 20. 12:57
2019-10-25 글쓴이 TED HONG

[Unity] UGUI 에서 터치 좌표에 UI가 있는지 판별하기

개발하다 보면 오브젝트의 Collider 와 UI의 구성요소가 겹치는 경우가 있는데
이 상태를 판별하는 코드이다.

        public static bool IsOverUIElement()
        {
            var eventData = new PointerEventData(EventSystem.current);
            eventData.position = Input.mousePosition;
            var results = new List<RaycastResult>();
            EventSystem.current.RaycastAll(eventData, results);
            return results.Count > 0;
        }