Unity2D:将我的播放器的移动距离限制为相机宽度的一半

时间:2018-04-10 23:44:15

标签: c# unity3d limit distance

我试图限制我的播放器离开某个区域的距离很麻烦,我想将距离缩短到我主摄像头宽度的一半,有没有办法这样做,这是我的代码:

更新编辑:

void Update () {
            if (Input.GetMouseButtonDown (0)) {
                if (EventSystem.current.currentSelectedGameObject)
                    return;
                Vector3 mousePosition = Input.mousePosition - target;
                mousePosition.z = 10;
                target = Camera.main.ScreenToWorldPoint (mousePosition);
                target.y = transform.position.y;


            } 
            transform.position = Vector3.MoveTowards (transform.position, target, moveSpeed * Time.deltaTime);
}

谢谢!

0 个答案:

没有答案