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));  
  
   }  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM