unity API 之EventSystem.current.IsPointerOverGameObject()
命名空间 :UnityEngine.EventSystems
官方描述:
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems; //备上空间名 public class MouseExample : MonoBehaviour
{
void Update()
{
// Check if the left mouse button was clicked
if (Input.GetMouseButtonDown(0))
{
// Check if the mouse was clicked over a UI element
if (EventSystem.current.IsPointerOverGameObject()) //检测是否点击了UI上的物件,返会bool值
{
Debug.Log("Clicked on the UI");
}
}
}
} 当使用触屏时,官方给出了另外一份代码
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems; public class TouchExample : MonoBehaviour
{
void Update()
{
// Check if there is a touch
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) //检测手值的触碰 // Check if finger is over a UI element
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) //监视是否触碰UI
{
Debug.Log("Touched the UI");
}
}
}
}
总结:可以用此API避免在画面中点击到UI的物件又同时点到Game中的物件触发的一些情况;在触屏中可以判断点击的手指并执行相应的函数事件。
unity API 之EventSystem.current.IsPointerOverGameObject()的更多相关文章
- UGUI EventSystem.current.IsPointerOverGameObject(),判断是否进入了UI上
EventSystem.current.IsPointerOverGameObject(); //返回一个布尔值,进入了UI上就返回true,用的时候要 using UnityEngine.Event ...
- Call requires API level 21(Current min is 16)
Call requires API level 21(Current min is 16) Android开发中,遇到类似这种问题,如何处理? 一种办法是提升sdk最低版本到21,在Android s ...
- all requires API level 3 (current min is 1)问题的解决
几次出现了all requires API level 3 (current min is 1)的错误,后来发现解决的方法是右键单击项目文件夹,选择Android Tools->Clear Li ...
- Call requires API level 3 (current min is 1)
结果出现“Call requires API level 3 (current min is 1): 解决方法: 在工程上点击右键 -> Android Tools -> Clear Li ...
- cocos2d-x于android在call to OpenGL ES API with no current context
一.问题: 正在使用JNI离Java(Android)侧 打回来C++(Cocos2d-x)该函数返回消息.Cocos2d-x花掉了 看看 Eclipse的Log中.显示 有 call to Open ...
- SimpleDateFormat 出现错误 Call requires API level 24 (current min is 15)
这个故事是这样的 今天写打卡时间的时候需要获取一下当前时间,然后我就写了一个这个 SimpleDateFormat sDF = new SimpleDateFormat("yyyy-MM ...
- Call requires API level 11 (current min is 8)报错
新建一个Android Application Project,其中MainActivity.java中报错如下 Call requires API level 11(current min is 8 ...
- Call requires API level 7 (current min is 1):(问题解决)
在一个导入的项目里修改加入webView的时候设置缩放属性的设置报错: Call requires API level 7 (current min is 1): android.webkit.Web ...
- call to OpenGL ES API with no current context 和Fatal signal 11
近日在用cocos2dx3.4的时候使用了JNI调用,发现一个现象 当不使用jni的时候全然正常.使用了jni后回去的全部文字都变成黑块,而且有概率程序崩溃.附带出了两个log call to Ope ...
随机推荐
- STM32的命名规范
STM32F407VET6 STM32F407代表的是芯片的型号后面的字符表示芯片的信息 V这一项代表引脚数,其中T代表36脚,C代表48脚,R代表64脚,V代表100脚,Z代表144脚,I代表176 ...
- spring mvc 映射与适配器
在深入学习Spring mvc 过程中,我们需要了解如下两个类: org.springframework.web.servlet.mvc.method.annotation.RequestMappin ...
- chrome小书签-实用的小功能-javascript代码段
1.打印页面的所有脚本引用文件及代码段: javascript:var scriptarray=document.getElementsByTagName("script");fo ...
- Linux 学习笔记 2:文件系统
1.文件系统层次结构 系统目录内容: /: 根目录(之后的/都是目录分隔符) /home:用户目录 /bin: Unix常用命令,如bash, date, cat, tar等 /sbin: 管理员命令 ...
- Vue添加jquer插件
一.现象 综合开发需要,需要引用使用 二.解决 1.先安装jquer插件,命令运行: npm i jquery --save-dev (tips: i 也就是 install --save-dev ...
- MongoDB学习记录(三) - MongoDB的"增查改删"操作之"查"
查找使用的方法: db.collection.find() 查找所有文档 db.collection.find({})或者db.collection.find({}) 指定键值对 db.collect ...
- #error "OpenCV 4.x+ requires enabled C++11 support"解决方法
报错的本质是需要c++11的支持,顾名思义,当前的编译环境是c++11以下的版本.我用的cmake编译,因此再cmakelists文件内添加设置c++标准为14就可以编译通过. )
- 虹软人脸检测和识别C# - API
using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D ...
- windows环境下wamp安装redis拓展
环境: wamp集成环境 安装分为两部 1.安装redis客户端 https://github.com/ServiceStack/redis-windows/raw/master/download ...
- Java: 集合类详解
0.参考文献 http://blog.csdn.net/liulin_good/article/details/6213815 1.java集合类图 1.1 1.2 上述类图中,实线边框的是实现类,比 ...