当前位置:网站首页>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 .
边栏推荐
- Sword finger offer day 2 linked list (simple)
- 1024水文
- And console Log say goodbye
- Assemble relevant knowledge points of flag bit (connected)
- leetcode:456. 132 模式【单调栈】
- 深圳民太安智能二面_秋招第一份offer
- Analyse de l'optimisation de la réécriture des requêtes lazyagg de l'entrepôt
- KVM script management - the road to dream
- 关于一个图书小系统的实现
- Which Chinese virtual human is better? Sullivan, IDC: Xiaobing Baidu Shangtang ranks in the first echelon
猜你喜欢

[pit avoidance refers to "difficult"] antd cascader implements new customized functions

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

剑指 Offer II 032. 有效的变位词

Sword finger offer day 1 stack and queue (simple)

Seven competencies required by architects

剑指 Offer II 025. 链表中的两数相加

Summer Ending

Conway's law can not be flexibly applied as an architect?

Common colors for drawing

Sword finger offer day 2 linked list (simple)
随机推荐
AI assisted paper drawing of PPT drawing
关于扫雷的简易实现
Oral English - continuous reading
Introduction to string 18 lectures Collection 4
1251- client does not support authentication protocol MySQL error resolution
汇编标志位相关知识点(连)
学习编程的起点。
提高排名的 15 个基本 SEO 技巧
几分钟上线一个网站 真是神器
Storage related contents of data in memory
剑指Offer 第 2 天链表(简单)
Drawing cubes with Visio
Sword finger offer day 1 stack and queue (simple)
J2EE from entry to earth 01 MySQL installation
KVM script management - the road to dream
Seven competencies required by architects
关于三子棋游戏的简易实现与N子棋胜利判断方法
Optimization of lazyagg query rewriting in parsing data warehouse
[machine learning] model and cost function
[pit avoidance refers to "difficult"] halfcheckedkeys rendering problem in semi selected status of antd tree