命名空间 :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. pwnable.kr-random-witeup

    看源代码. 可知,在linux下生成个随机数在于输入数异或等于固定值即可,而且吧, 随机数是固定的. 先得出随机数. random=1804289383 OK,接下来用计算器异或就行啦.0xB526F ...

  2. CentOS7+CDH5.14.0安装全流程记录,图文详解全程实测-总目录

    CentOS7+CDH5.14.0安装全流程记录,图文详解全程实测-总目录: 0.Windows 10本机下载Xshell,以方便往Linux主机上上传大文件 1.CentOS7+CDH5.14.0安 ...

  3. python的os模块fnmatch模块介绍

    一.先介绍一下os模块 import os print(os.getcwd()) # E:\python\test\python_models # 获取当前的目录 print(os.listdir(& ...

  4. android一个app打开另一个app的指定页面

    一个app打开另一个app的指定页面方法 有以下几种 1.通过包名.类名 2.通过intent的 action 3.通过Url 方案1. ComponentName componentName = n ...

  5. Redis分布式缓存

    Redis 主 slave 数据库优化-- 加inex, 分区 JVM调优--参数设置,比如偏向于计算的如何设置? 线程池:queue放满了之后,有什么方式能让他不拒绝掉?blockqueue就等在那 ...

  6. Kubernetes helm配置国内镜像源

    1.删除默认的源 helm repo remove stable 2.增加新的国内镜像源 helm repo add stable https://burdenbear.github.io/kube- ...

  7. 第二期,问道PC端游戏免安装,下载即可体验

    最近 迷恋游戏搭建不能自拔.搭建过 手游梦幻诛仙,传奇等等. 今天还是推荐PC端的问道这款游戏,原因是个人投入修改的时间太多了.基本完善了好多.这还得感谢这都是论坛的各位大佬体验的结果. 原来这个游戏 ...

  8. return this 和return * this

    this是指向自身对象的指针,*this是自身对象. 也就是说return *this返回的是当前对象的克隆或者本身(若返回类型为A, 则是克隆, 若返回类型为A&, 则是本身 ). retu ...

  9. Servlet之监听器(Listener)

    一.监听器(Listener)概述 1.概念 JavaWeb中的监听器是Servlet规范中定义的一种特殊类,它用于监听web应用程序中的ServletContext, HttpSession和 Se ...

  10. MyBatis updateByExample和updateByExampleSelective的区别

    大家都用过mybatis generator来生产数据库的xml文件,但是关于updateByExample和updateByExampleSelective的区别我之前一直分不太清楚. 如果分不清楚 ...