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控件)

posted @ 2019-09-03 21:08  阿土仔  阅读(308)  评论(0编辑  收藏  举报