首页 > 其他分享 >Unity检测鼠标是否与UI交互

Unity检测鼠标是否与UI交互

时间:2022-11-17 18:37:55浏览次数:48  
标签:return 鼠标 EventSystem Unity UI 交互

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

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

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

if (InteractWithUI()) return;

标签:return,鼠标,EventSystem,Unity,UI,交互
From: https://www.cnblogs.com/AlexNJW/p/16900379.html

相关文章