unity判断是否点击了UI界面

1.判断是否点击 UGUI界面:

using UnityEngine;  
using System.Collections;  
using UnityEngine.UI;  
using UnityEngine.EventSystems;  
public class UiClickTest : MonoBehaviour {  
  
    // Use this for initialization  
    void Start () {  
      
    }  
      
    // Update is called once per frame  
    void Update () {  
  
        if (Input.GetMouseButtonDown(0)) {  
            if (EventSystem.current.IsPointerOverGameObject()) {  
                Debug.Log("点击到UGUI的UI界面,会返回true");  
            } else {  
                Debug.Log("如果没点击到UGUI上的任何东西,就会返回false");  
            }  
        }  
    }  
}  

2.判断是否点击了NGUI界面:

void OnClick ()  
{  
    // NGUI 3.8之前 点击空白地方返回为null  
    // NGUI 3.8之后 点击空白地方返回为UIRoot  
    if (UICamera.hoveredObject.name != "UIRoot")  
    {  
        Debug.Log ("我现在点击的不是空白");  
    }  
}  

void Update()  
   {  
       // 返回值是bool变量,如果鼠标在UI上返回true(记得加碰撞器)  
    Debug.Log(UICamera.Raycast(Input.mousePosition));  
  
   }  
原文地址:https://www.cnblogs.com/lichuangblog/p/7520677.html