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

2023-02-13,,,,

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() && EventSystem.current.IsPointerOverGameObject() == false)
{
Debug.Log("右键没有点在UI上...");
}
else if (Input.GetMouseButtonDown() && EventSystem.current.IsPointerOverGameObject() == true)
{
Debug.Log("右键点在了UI上...");
}
}
}

2.新建一个Image ,如图:

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

UGUI EventSystem.current.IsPointerOverGameObject(),判断是否进入了UI上的相关教程结束。

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

下载本文的Word格式文档,以方便收藏与打印。