UGUI - 判断是否点击在UI 上 Bug,IsPointerOverGameObject()在移动端检测失败
UGUI 提供了一个检测是否点击在UI上的方法
EventSystem.current.IsPointerOverGameObject();
但是该方法在PC上检测正常,结果拿到Android真机测试上,永远检测不到。
在网上找了一些大神的解决方案
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class ClickIsOverUI {
public static ClickIsOverUI Instance = new ClickIsOverUI();
public ClickIsOverUI()
{
}
//方法一, 使用该方法的另一个重载方法,使用时给该方法传递一个整形参数
// 该参数即使触摸手势的 id
// int id = Input.GetTouch(0).fingerId;
public bool IsPointerOverUIObject(int fingerID)
{
return EventSystem.current.IsPointerOverGameObject(fingerID);
}
//方法二 通过UI事件发射射线
//是 2D UI 的位置,非 3D 位置
public bool IsPointerOverUIObject(