强悍の绝巴哈

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

在Unity项目中,假设在鼠标按键时会触发游戏内的操作,但是在鼠标与UI进行交互时我们希望停止游戏中的操作,这是需要使用EventSystem中的方法来检测鼠标是否正在与UI交互

private bool InteractWithUI()
{
    if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
        return true;
    return false;
}

在接下来的鼠标检测之前加入调用该方法即可在鼠标与UI进行交互时屏蔽游戏内操作

if (InteractWithUI()) return;
posted on 2022-11-17 18:21  强悍の绝巴哈  阅读(381)  评论(0编辑  收藏  举报