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 ,如图:

UGUI  EventSystem.current.IsPointerOverGameObject(),判断是否进入了UI上

3.运行,试着用右键点击空白处,再试着点击Image试试;把Image的RaycastTarget钩子去掉再试试.

UGUI  EventSystem.current.IsPointerOverGameObject(),判断是否进入了UI上

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2021-09-14
  • 2022-12-23
  • 2022-03-05
  • 2022-02-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-02-27
  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案