블로그 이미지
1인 개발자 (므쮸 컴퍼니) 개인 블로그 입니다. MMZZUU

카테고리

므쮸 컴퍼니 (22)
▣ Game (3)
▣ Unity 게임 만들기 (14)
▣ 정보공유 (5)
Total
Today
Yesterday

유니티에서 UI객체를 클릭 혹은 터치를 했을 때 게임 중 입력 이벤트를 처리하는 부분과 같이 처리되는 문제가 발생하는 경우가 많은데요~


이런경우엔,




using UnityEngine.EventSystems;


...


if (EventSystem.current.IsPointerOverGameObject(pointId)return;




EventSystem.current.IsPointerOverGameObject(pointId)


함수는 포인터가 중간에 UI객체를 만나면 true 를 뱉어내는 함수입니다.


pointId : 터치 또는 마우스 ID 입니다


요걸로 게임중 입력이벤트 이전에 컷트해버리는 식으로 처리하면 됩니다.




예제코딩


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void Update () {
    if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) {
        if (Input.touchCount > 0)
        {
            for (int i = 0; i < Input.touchCount; i++) {
                if (EventSystem.current.IsPointerOverGameObject(i))
                    return;
            }
        }
        print ("터치!!!");
    } else {
        if (Input.GetMouseButtonDown (0)) {
            if (EventSystem.current.IsPointerOverGameObject())
                return;
            print ("클릭!!!");
        }
    }
}
cs


위 코딩으로 테스트 해보시면 모바일 터치환경과 에디터환경에서 테스트 차이를 확인가능합니다.

Posted by MMZZUU
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함