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 ...
随机推荐
- POJ-3660.Cow Contest(有向图的传递闭包)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17797 Accepted: 9893 De ...
- 微信小程序开发——使用mock数据模拟api请求
前言: 微信小程序开发中,后端提供了接口设计文档,前端可以先mock数据模拟api请求进行开发调试,而且可以根据需要设计mock文件的格式和内容,这样在后端接口开发完成之前,前端可以最大限度的完成前端 ...
- python3作业:模拟登录
__author__ = "bin007" customer = {}#存储用户信息#处理用户信息文件try: with open('login.txt','r',encoding ...
- jsp3
普通传值: a1.jsp <form action="a2.jsp" method="post"> 用户名:<input type=" ...
- Checkbox的只读设置
readonly和disabled属性均不生效.可按如下方式处理,记得引入jquery.js文件 <input type="checkbox" name="chk& ...
- mysql学习3:mysql之my.cnf详解
mysql之my.cnf详解 本文转自:https://www.cnblogs.com/panwenbin-logs/p/8360703.html 以下是 my.cnf 配置文件参数解释: #*** ...
- ubuntu 下安装pip3
在使用任何apt 安装任何软件包之前,建议用以下命令更新软件 sudo apt update 更新好了后可能会出现 apt list --upgradable 安装pip3 sudo apt inst ...
- 安装Pygame(Python3.6,windows)
1. 本机为python3.6的环境 2. 到pygame官网下载对应系统,对应python版本的pygame文件,下载地址:https://pypi.python.org/pypi/Pygame/1 ...
- 安卓学习 Drawable对象
whie(!images[currentImage].endWith(".PNG")&&!images[currentImage].endWith(".p ...
- node.js 线程调试配置
{ // 使用 IntelliSense 了解相关属性. // 悬停以查看现有属性的描述. // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linki ...