当前位置:网站首页>How unity makes the UI intercept click events
How unity makes the UI intercept click events
2022-06-25 13:17:00 【acgCode】
stay Unity It is often necessary to make pop-up windows during game development . Pop up creation in Canvas in , Have a lot of UI Components can be used .
In the actual use of the process found , The pop-up window cannot intercept the mouse click event .Canvas hinder GameObject If there are bound collider components and triggers , Click on the event to penetrate UI Behind the trigger GameObject Click events for .
The official has provided testing methods , I will explain it in detail below :
First, you need to introduce namespaces before the code .
using UnityEngine.EventSystems;
After the GameObject Add a judgment to the mouse click event :
private void OnMouseUpAsButton()
{
if (EventSystem.current.IsPointerOverGameObject()) {
return;
}
// TODO The logic to be executed later
}
It's on it PC End of the judgment , The mobile terminal should write this :
private void OnMouseUpAsButton()
{
// Disable multi touch
if (Input.touchCount == 1 && EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) {
return;
}
// TODO The logic to be executed later
}
such GameObject There is one ahead UI When , The subsequent logic will not be executed , Thus, a mouse click event is blocked .
Of course, if game logic and interactive judgment are written in Update Words in Li , This judgment can also be added to Update in , So as to play the role of interception . Introduce as needed .
边栏推荐
- 汇编标志位相关知识点(连)
- Analyse de l'optimisation de la réécriture des requêtes lazyagg de l'entrepôt
- 药物设计新福音:腾讯联合中科大、浙大开发自适应图学习方法,预测分子相互作用及分子性质
- [visio] solving the fuzzy problem of parallelogram in word
- 字节跳动Dev Better技术沙龙来啦!参与活动赢好礼,限时免费报名中!
- 与生产环境中的 console.log 说再见
- Resolution of PPT paper drawing
- nacos无法修改配置文件Mysql8.0的解决方法
- MySQL learning notes
- KVM script management - the road to dream
猜你喜欢

Optimization of lazyagg query rewriting in parsing data warehouse

Three lines of code to simply modify the project code of the jar package

CUDA error: unspecified launch failure

Sword finger offer day 1 stack and queue (simple)

Sword finger offer day 2 linked list (simple)

J2EE从入门到入土01.MySQL安装

二叉树之_哈夫曼树_哈弗曼编码

Introduction to mongodb chapter 01 introduction to mongodb

Resolution of PPT paper drawing

[pit avoidance refers to "difficult"] antd cascader implements new customized functions
随机推荐
.NET in China - What's New in .NET
[machine learning] what is machine learning?
深圳民太安智能二面_秋招第一份offer
关于扫雷的简易实现
数据在内存中的存储相关内容
Update PIP & Download jupyter Lab
Some knowledge about structure, enumeration and union
Of binary tree_ Huffman tree_ Huffman encoding
量化交易之回测篇 - 期货CTA策略实例(TQZFutureRenkoScalpingStrategy)
LeetCode链表题解技巧归纳总结
《MongoDB入门教程》第01篇 MongoDB简介
Pointer, it has to say that the subject
An article clearly explains MySQL's clustering / Federation / coverage index, back to table, and index push down
Using swiper to realize seamless rotation of multiple slides
數據在內存中的存儲相關內容
关于数据在内存中的存储下
买基金在哪里开户安全?还请赐教
New Gospel of drug design: Tencent, together with China University of science and technology and Zhejiang University, developed an adaptive graph learning method to predict molecular interactions and
[pit avoidance refers to "difficult"] halfcheckedkeys rendering problem in semi selected status of antd tree
golang键盘输入语句scanln scanf代码示例