首页 > 解决方案 > 触摸UI时防止移动的方法?

问题描述

随着时间的推移,当我触摸到某个点时,我想移动我的角色。但如果触摸点是 UI 元素,我不希望它定位。我通过鼠标单击 PC 来实现这一点,但在 Android 上却没有。

PC鼠标点击没有问题:

if (Input.GetMouseButton(0)) {
    if (!EventSystem.current.IsPointerOverGameObject()){
       Target = Camera.main.ScreenToWorldPoint(Input.mousePosition); 
    } 
}

点击时仍向 UI 移动的 Android 触摸:

if (Input.touchCount > 0){ 
    foreach (Touch touch in Input.touches){
        int id = touch.fingerId;

        if (!EventSystem.current.IsPointerOverGameObject(id))
        {
            Target = Camera.main.ScreenToWorldPoint(touch.position);
        }
    }
}

有任何想法吗?

标签: unity3dcontrols

解决方案


推荐阅读