UGUI防止穿透和判断点击的是否是UI

   #if IPHONE || ANDROID
    if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
#else
    if (EventSystem.current.IsPointerOverGameObject())
#endif
        Debug.Log("当前触摸在UI上");
            
    else 
           Debug.Log("当前没有触摸在UI上");

       注意EventSystem.current.IsPointerOverGameObject是指点击的物体是否是一个能响应EventSystem的物体(也就是UGUI控件)

猜你喜欢

转载自www.cnblogs.com/bearhb/p/11455684.html