EventSystem.IsPointerOverGameObject
public bool IsPointerOverGameObject();
public bool IsPointerOverGameObject(int pointerId);
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"); } } } }