Programming/Unity
[Unity3D] 마우스 클릭 시 UI인지 3D객체 인지 구별
타임박스
2020. 10. 16. 13:43
반응형
✔ Unity3D
UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()
UI에 가려져있는 3D 오브젝트 객체가 마우스 클릭 시 OnMouseDown()이나 OnMouseUp() 이벤트 콜이 된다.
UI인지 판별하는 방법은 간단하다.
EventSystem.current에서 현재 클릭한 이벤트에 대한 정보를 확인할 수 있다.
public void OnMouseDown()
{
if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject() == true)
return;
// do..
}
EventSystem.currrent.IsPointerOverGameObject() == true 일 경우 => UI 클릭 됨.
반대로 false의 경우에는 UI 클릭이 일어나지 않았다고 보면된다.
반응형