Unity防止鼠标点透UI影响到被UI遮挡的游戏物体

其实就很简单的一句话  

如  

   private IEnumerator OnMouseDown()
    {
        if (!EventSystem.current.IsPointerOverGameObject())
        {

        //选中被点击的物体

        }

}

就是加上EventSystem.current.IsPointerOverGameObject()这个判断   这段代码是  具有给定ID的指针是否位于EventSystem对象上   也就是说判断鼠标指针是否在UI上 

猜你喜欢

转载自blog.csdn.net/weixin_41573444/article/details/90269080
今日推荐