当前位置:网站首页>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 .
边栏推荐
- Back test of quantitative trading - tqzfuturerenkowavestrategy
- 20220620 interview reply
- Online service emergency research methodology
- JVM参数解释
- J2EE从入门到入土01.MySQL安装
- 剑指offer 第 3 天字符串(简单)
- Update PIP & Download jupyter Lab
- leetcode:918. 环形子数组的最大和【逆向思维 + 最大子数组和】
- Summer Ending
- Detailed explanation of string operation functions and memory functions
猜你喜欢
中国虚拟人哪家强?沙利文、IDC:小冰百度商汤位列第一梯队
J2EE从入门到入土01.MySQL安装
深圳民太安智能二面_秋招第一份offer
Which Chinese virtual human is better? Sullivan, IDC: Xiaobing Baidu Shangtang ranks in the first echelon
Solution to Nacos' failure to modify the configuration file mysql8.0
Storage related contents of data in memory
Koa 框架
Django框架——缓存、信号、跨站请求伪造、 跨域问题、cookie-session-token
三行代码简单修改jar包的项目代码
KDD 2022 | GraphMAE:自监督掩码图自编码器
随机推荐
Back test of quantitative trading - tqzfuturerenkowavestrategy
1024水文
Django framework - caching, signaling, cross site request forgery, cross domain issues, cookie session token
几分钟上线一个网站 真是神器
Stockage des données en mémoire
[visio] solving the fuzzy problem of parallelogram in word
CUDA error: unspecified launch failure
Reload cuda/cudnn/pytorch
J2EE from entry to earth 01 MySQL installation
Online service emergency research methodology
Restful and RPC
关于扫雷的简易实现
Koa 框架
字符串入门十八讲合集四
515. Find Largest Value in Each Tree Row
Solve the problem that yarn cannot load files in vs Code
字节跳动Dev Better技术沙龙来啦!参与活动赢好礼,限时免费报名中!
[flask tutorial] flask development foundation and introduction
关于结构体,枚举,联合的一些知识
Shenzhen mintai'an intelligent second side_ The first offer of autumn recruitment