重点在下面↓↓↓↓↓↓
重点在下面↓↓↓↓↓↓
重点在下面↓↓↓↓↓↓
重要的事要说三次
目前找到的方式
移动端
int fingerId = Input.GetTouch(0).fingerId;
if (EventSystem.current.IsPointerOverGameObject(fingerId))
{
Debug.Log("点击到UI");
}
其他
EventSystem.current.IsPointerOverGameObject()
上面两种在某些情况下好使
目前我使用的方式
/// <summary>
/// 判断是否触摸到UI
/// </summary>
/// <returns></returns>
public bool IsTouchUI
{
get
{
GameObject currentSelectedGameObject = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;
if (currentSelectedGameObject != null)
{
// UI 层固定值为5 。不喜欢可以换成LayerMask 获取
if (currentSelectedGameObject.layer == 5)
{
return true;
}
}
return false;
}
}
目前用起来。还没发现什么问题