命名空间 :UnityEngine.EventSystems

官方描述:

public bool IsPointerOverGameObject();
public bool IsPointerOverGameObject(int pointerId);        //触摸屏时需要的参数,即检测触碰的手值
 
Is the pointer with the given ID over an EventSystem object?
 
代码:
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()的更多相关文章

  1. UGUI EventSystem.current.IsPointerOverGameObject(),判断是否进入了UI上

    EventSystem.current.IsPointerOverGameObject(); //返回一个布尔值,进入了UI上就返回true,用的时候要 using UnityEngine.Event ...

  2. Call requires API level 21(Current min is 16)

    Call requires API level 21(Current min is 16) Android开发中,遇到类似这种问题,如何处理? 一种办法是提升sdk最低版本到21,在Android s ...

  3. all requires API level 3 (current min is 1)问题的解决

    几次出现了all requires API level 3 (current min is 1)的错误,后来发现解决的方法是右键单击项目文件夹,选择Android Tools->Clear Li ...

  4. Call requires API level 3 (current min is 1)

    结果出现“Call requires API level 3 (current min is 1): 解决方法: 在工程上点击右键 -> Android Tools -> Clear Li ...

  5. 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 ...

  6. SimpleDateFormat 出现错误 Call requires API level 24 (current min is 15)

    这个故事是这样的 今天写打卡时间的时候需要获取一下当前时间,然后我就写了一个这个 SimpleDateFormat sDF =   new SimpleDateFormat("yyyy-MM ...

  7. Call requires API level 11 (current min is 8)报错

    新建一个Android Application Project,其中MainActivity.java中报错如下 Call requires API level 11(current min is 8 ...

  8. Call requires API level 7 (current min is 1):(问题解决)

    在一个导入的项目里修改加入webView的时候设置缩放属性的设置报错: Call requires API level 7 (current min is 1): android.webkit.Web ...

  9. call to OpenGL ES API with no current context 和Fatal signal 11

    近日在用cocos2dx3.4的时候使用了JNI调用,发现一个现象 当不使用jni的时候全然正常.使用了jni后回去的全部文字都变成黑块,而且有概率程序崩溃.附带出了两个log call to Ope ...

随机推荐

  1. 网络通信实验(2)TCP/IP LWIP 简介

    TCP/IP 简介 TCP/IP 中文名为传输控制协议/因特网互联协议,又名网络通讯协议,是 Internet 最基本的协议. Internet 国际互联网络的基础,由网络层的 IP 协议和传输层的 ...

  2. Hillstone设备管理-设备软件Stone-OS升级

    1.通过sysloader进行StoneOS升级 1)给设备上电按提示按ESC并且进入 Sysloader.参照以下操作提示: 2)在下面选择对应的选项升级os,可以通过tftp.ftp.usb.系统 ...

  3. mysql数据库优化(转)

    今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数据 ...

  4. java_30对文件的操作

    1.导包 导commons-io-2.4.jar包 2. public class Demo1Commons { public static void main(String[] args) { fu ...

  5. koa中间件

    koa是Express的下一代基于node的web框架  目前有1.x和2.0两个版本 1. Express Express是第一代最流行的web框架  它对node.js的http进行了封装 Exp ...

  6. 使用Jmeter连接数据库检查数据库记录的方法

    一.首先下载Jdbc驱动(jdbc驱动分两种,classes与ojdbc文件,该用哪个需要检查电脑安装的jdk版本(查看方法cmd命令java –version) 关于各种版本的说明:http://e ...

  7. Flask 验证码 点击验证码刷新

    ---恢复内容开始--- import random import string # Image:一个画布 # ImageDraw:一个画笔 # ImageFont:画笔的字体 # pip insta ...

  8. node 常用模块及方法fs,url,http,path

    http://www.cnblogs.com/mangoxin/p/5664615.html https://www.liaoxuefeng.com/wiki/001434446689867b2715 ...

  9. 加密 解密 RSA & AES & DES

    git: https://github.com/XHTeng/XHCryptorTools rsa RSA加解密中必须考虑到的密钥长度.明文长度和密文长度问题.明文长度需要小于密钥长度,而密文长度则等 ...

  10. Maven学习 七 Maven项目创建(2)war项目

    一.web项目的目录结构 如果手动创建一个java  web项目,其基本的目录结构包括:METE-INF,WEB-INF,以及WEB-INF下必须包含一个web.xml文件 二.使用Maven创建wa ...