在unity中,判断鼠标点击的是UI还是物体

如果两个重叠了,那么点击的是UI,代码如下:

void Update () {
    if (EventSystem.current.IsPointerOverGameObject()){
        return;//为真,则点击在UI上}
    if (Input.GetMouseButtonDown(0)){
        //其他操作
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_39874268/article/details/81867908