EventSystem.IsPointerOverGameObject
Parameters
pointerId | Pointer (touch / mouse) ID. |
Description
Is the pointer with the given ID over an EventSystem object?
using UnityEngine; using System.Collections; using UnityEngine.EventSystems;
public class MouseExample : MonoBehaviour { void Update() { // Check if the left mouse button was clicked if (Input.GetMouseButtonDown(0)) { // Check if the mouse was clicked over a UI element if (EventSystem.current.IsPointerOverGameObject()) { Debug.Log("Clicked on the UI"); } } } }
using UnityEngine; using System.Collections; using UnityEngine.EventSystems;
public class TouchExample : MonoBehaviour { void Update() { // Check if there is a touch if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { // Check if finger is over a UI element if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) { Debug.Log("Touched the UI"); } } } }
If you use IsPointerOverGameObject() without a parameter, it points to the "left mouse button" (pointerId = -1); therefore when you use IsPointerOverGameObject for touch, you should consider passing a pointerId to it.
Note that for touch, IsPointerOverGameObject should be used with OnMouseDown() or Input.GetMouseButtonDown(0) or Input.GetTouch(0).phase == TouchPhase.Began.
매개 변수없이 IsPointerOverGameObject()를 사용하면 "마우스 왼쪽 버튼"(pointerId = -1)을 가리 킵니다. 따라서 touch에 IsPointerOverGameObject를 사용할 때는 pointerId를 전달하는 것을 고려해야합니다.
touch의 경우 IsPointerOverGameObject는 OnMouseDown () 또는 Input.GetMouseButtonDown (0) 또는 Input.GetTouch (0) .phase == TouchPhase.Began과 함께 사용해야합니다.
오버로드는 다음처럼 정의되어있다
//
// 요약:
// ///
// Is the pointer with the given ID over an EventSystem object?
// ///
//
// 매개 변수:
// pointerId:
// Pointer (touch / mouse) ID.
public bool IsPointerOverGameObject(int pointerId);
//
// 요약:
// ///
// Is the pointer with the given ID over an EventSystem object?
// ///
//
// 매개 변수:
// pointerId:
// Pointer (touch / mouse) ID.
public bool IsPointerOverGameObject();
'게임엔진(GameEngine) > Unity3D' 카테고리의 다른 글
NavMeshAgent and collision (0) | 2018.01.14 |
---|---|
AnimationState.normalizedTime (0) | 2018.01.14 |
Important lightmap setting (0) | 2018.01.06 |
Unity3D - 최적화를 위한 CombineMesh (0) | 2018.01.06 |
Material doesn't have stencil properties (1) | 2017.12.29 |