当前位置:网站首页>【Unity】判断鼠标是否点击在UI上
【Unity】判断鼠标是否点击在UI上
2022-08-09 01:16:00 【DAGUNIANGZHOU】
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class TestUI : MonoBehaviour
{
void Update()
{
if (IsPointerOverGameObject(Input.mousePosition))
{
Debug.Log("点击到UI");
}
}
private bool IsPointerOverGameObject(Vector2 mousePosition)
{
//创建一个点击事件
PointerEventData eventData = new PointerEventData(EventSystem.current);
eventData.position = mousePosition;
List<RaycastResult> raycastResults = new List<RaycastResult>();
//向点击位置发射一条射线,检测是否点击UI
EventSystem.current.RaycastAll(eventData, raycastResults);
if (raycastResults.Count > 0)
{
return true;
}
else
{
return false;
}
}
}
边栏推荐
猜你喜欢
Non-major graduates, five-faced Ali: Four rounds of technical + HR have already taken an offer
jetson nano 开机闪一下然后黑屏
如何在EasyDSS中使用ffmpeg实现点播视频的拼接与合成?
如何仿造一个websocket请求?
微信企业号开发之获取AccessToken
Using MySQL in Ubuntu/Linux environment: Modify the database sql_mode to solve the "this is incompatible with sql_mode=only_full_group_by" problem
《Go语言学习:基本变量与类型》
makefile文件编译
日文翻译-在线免费日文翻译软件
任务六 特征衍生 案例分析
随机推荐
Loadrunner结合Fiddler实现脚本的录制
低代码接口开发平台——YesApi(API+数据表单)
任务六 特征衍生 案例分析
gstreamer 记录
轻量级CNN网络高效设计准则-ShuffleNet v2学习记录
使用百度EasyDL实现智能垃圾箱
4-4 Matplotlib库 直方图
保护您的 Web 应用程序的最佳开源 Web 应用程序防火墙
如何准备一份简历
【物理应用】基于El-centro地震波作用下隔震与非隔震支座下的顶层位移、速度、加速度的对比情况附matlab代码
Use Ehcache distributed cache to easily create commercial-grade high-concurrency, high-performance API interfaces!
Wireshark packet capture tool
远程控制项目遇到的bug
猿辅导联合多方专家共议新课标:语文将更强调“实践性”
tf.pad()--填充操作
STM32H750VBT6 Keil5 error :flash download failed cortex-M7
Dapr学习(4)之eShopOnDapr部署(Rancher2.63&k3s)
【.NET 6】开发minimal api以及依赖注入的实现和代码演示
轻量级神经网络SqueezeNext--考虑硬件提速
LeetCode精选200道--字符串篇