命名空间 :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. margin-top / padding-top 的百分比 到底是多少?

    之前,我以为 margin-top/padding-top 如果设置成%,得到的是 基于父对象总高度的百分比. 但是,这种想法是错的.因为在CSS标准里,是基于父对象宽度的百分比. <style ...

  2. java 坑总结

    1.Cannot find current proxy: Set 'exposeProxy' property on Advised to 'true' to make it available. 解 ...

  3. jquery 全选、反选、获取值、背景行、隔行变色和鼠标略过变色变色全特效

    好久没有写东西了,当然不是没东西可写,只是没有时间写.今天抽出点时间来把我最近使用的一些 Javascript 特效的东西贴出来,供自己或者别人查询使用.最近我在做一个新的 B/S 系统,由于没有专门 ...

  4. devexpress总结 accordionControl 加载panelcontrol 的快捷方式

    先说保存: UserControl control; private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars. ...

  5. MUI 添加自定义图标(注意点)

    参考: https://blog.csdn.net/qq_39759115/article/details/79436606 注意: 1. 将这个原来的逗号改成分号 2. 这些图标的名字都可以改名字

  6. dskinlite(uieasy mfc界面库)使用记录4:绘制动态元素(listbox)

    效果图: XML代码: 299行的headerctrl只针对listview有效,这里是listbox,忽略 wirelessName,wirelessStatus,wirelessSignal会通过 ...

  7. IE 11和const的兼容问题

    说好的IE11兼容javascript中的常量类型 const 呢 ?可能并没有完全兼容 项目中遇到一个问题,采用google浏览器访问没问题,在本地jetty启动,IE11也可以正常访问,然而当我将 ...

  8. Effective C++ 笔记:条款 33 避免继承导致的名称遮掩

    Avoid hiding inherited names 作用域(scopes)所带来的名称二义性,c++编译器会寻找指涉(refer to)的对象并实现名称遮掩规则(name-hiding rule ...

  9. lnmp 搭建 svn服务

    服务器环境 lnmp  环境搭建地址:https://lnmp.org/install.html 注意事项  服务器必须开放3690端口 安装过程 1.yum install subversion(安 ...

  10. Java JSONArray for循环 remove成员的一个好算法

    好久没写日志了,今天来写一个,JSONArry fro循环判断value,移除不需要的,不需再将JSONArry再次转换成 map或list. JSONArray移除成员只能通过for遍历取成员,判断 ...