当前位置:网站首页>【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;
}
}
}
边栏推荐
- CondConv--动态卷积思想
- 微信企业号开发之开启回调模式
- qps tps rps 区别
- Sencha Touch页面跳转创建返回上一级按钮的设计思路
- Use Ehcache distributed cache to easily create commercial-grade high-concurrency, high-performance API interfaces!
- 谷歌翻译下载-免费谷歌翻译软件下载
- 2022年中国全民健身发展白皮书
- 4-7 Matplotlib库 箱线图
- "Replay" interview BAMT came back to sort out 398 high-frequency interview questions to help you get a high salary offer
- 4-4 Matplotlib库 直方图
猜你喜欢
随机推荐
轻量级网络SqueezeNet学习记录
观察者模式
低代码接口开发平台——YesApi(API+数据表单)
深度学习模型的两种部署:ONNX与Caffe
5-5 Seaborn库FacetGrid结构图
seaborn 笔记: 绘制分类数据
【物理应用】基于El-centro地震波作用下隔震与非隔震支座下的顶层位移、速度、加速度的对比情况附matlab代码
谷歌翻译下载-免费谷歌翻译软件下载
Unified identity management platform IAM single sign-on process and third-party interface design scheme
ONNX是什么?怎么用?[简明解读版]
最新豆瓣top250爬虫案例代码分析[注释齐全]
[Signal denoising] Based on Sage-Husa adaptive Kalman filter to realize the suppression of ocean wave magnetic field noise and the generation of ocean wave magnetic field noise with matlab code
《Go语言学习:基本变量与类型》
Sencha Touch页面跳转创建返回上一级按钮的设计思路
4-9 Matplotlib图结构分析
C语言-大端存储和小端存储
走向合规化的虚拟人直播
4-4 Matplotlib库 直方图
4-11 Matplotlib 配置
微信企业号开发之获取AccessToken