UGUI EventSystem.current.IsPointerOverGameObject(),判斷是否進入了UI上


EventSystem.current.IsPointerOverGameObject(); //返回一個布爾值,進入了UI上就返回true,用的時候要 using UnityEngine.EventSystems;

 

1.寫一個腳本掛到相機上,如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Test : MonoBehaviour {

    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        if (Input.GetMouseButtonDown(0) && EventSystem.current.IsPointerOverGameObject() == false)
        {
            Debug.Log("右鍵沒有點在UI上...");
        }
        else if (Input.GetMouseButtonDown(0) && EventSystem.current.IsPointerOverGameObject() == true)
        {
            Debug.Log("右鍵點在了UI上...");
        }
    }
}

2.新建一個Image ,如圖:

3.運行,試着用右鍵點擊空白處,再試着點擊Image試試;把Image的RaycastTarget鈎子去掉再試試.

 


免責聲明!

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



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