命名空间 :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. c# 域名转换成ip地址

    tcp协议发送到某个地址端口号是,地址是域名3322.net类型,转换成ip地址.亲测两种方法都可以. 1.参考https://blog.csdn.net/szsbell/article/detail ...

  2. HTTPClient to use http/https protocol to send request

    使用了spring boot, gradle, commons-httpcomponent3. 目前httpclient 已经有了版本4. https://github.com/lvfe/httpCl ...

  3. 机器学习--Lasso回归和岭回归

    之前我们介绍了多元线性回归的原理, 又通过一个案例对多元线性回归模型进一步了解, 其中谈到自变量之间存在高度相关, 容易产生多重共线性问题, 对于多重共线性问题的解决方法有: 删除自变量, 改变数据形 ...

  4. Linux-Slabinfo

    1.内存管理有两个算法:伙伴算法(buddy system)和slab算法.伙伴算法是以页为单位管理内存,slab算法是以字节为单位管理内存,是内核的小内存管理算法.特点是基于对象进行管理. slab ...

  5. mysql 悲观锁与乐观锁的理解

    悲观锁与乐观锁是人们定义出来的概念,你可以理解为一种思想,是处理并发资源的常用手段. 不要把他们与mysql中提供的锁机制(表锁,行锁,排他锁,共享锁)混为一谈. 一.悲观锁 顾名思义,就是对于数据的 ...

  6. 【转】一个 Linux 上分析死锁的简单方法

    简介 死锁 (deallocks): 是指两个或两个以上的进程(线程)在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统产生了死锁,这 ...

  7. Google关于Spanner的论文中分布式事务的实现

    Google关于Spanner的论文中分布式事务的实现 Google在Spanner相关的论文中详细的解释了Percolator分布式事务的实现方式, 而且用简洁的伪代码示例怎么实现分布式事务; Pe ...

  8. c语言01次作业--分支,顺序结构

    C语言--第01次作业 1.1思维导图 1.2本章学习体会及代码量学习体会 1.2.1学习体会 本章学习让我体会良多.首先,不得不承认自己是一个非常马虎的人.常见的问题就是输出格式上常因为没有与题目要 ...

  9. bower简明入门教程

    什么是bower: Bower是一个客户端技术的软件包管理器,它可用于搜索.安装和卸载如JavaScript.HTML.CSS之类的网络资源.其他一些建立在Bower基础之上的开发工具,如YeoMan ...

  10. django model设计与实际数据库表的对比

    # 文章class Article(models.Model): title = models.CharField('标题', max_length=70) excerpt = models.Text ...