【问题标题】:Unity3d move camera using mouse wheelUnity3d 使用鼠标滚轮移动相机
【发布时间】:2016-11-27 15:09:34
【问题描述】:

我正在尝试制作简单的产品可视化。我想将相机缩放或移动到物体上。我的代码如下所示:

    public class mouseMover : MonoBehaviour {

        public Transform target;
        public float speed;


        void Update () {

            if (Input.GetAxis ("Mouse ScrollWheel") < 0) {
                float scroll = Input.GetAxis ("Mouse ScrollWheel");

                transform.LookAt (target);
                transform.Translate(0, 0, scroll * speed, Space.World);


            }

            if (Input.GetAxis ("Mouse ScrollWheel") > 0) {

                float scroll = Input.GetAxis ("Mouse ScrollWheel");
                transform.LookAt (target);
                transform.Translate(0, 0, scroll * speed, Space.World);
            }

    }

}

但是当我尝试缩放时,它只是围绕对象“飞”,当相机到达对象的另一侧时,它开始后退。

【问题讨论】:

    标签: unity3d camera


    【解决方案1】:

    这是因为你使用 Space.World 而不是 Space.Self :

    void Update ()
    {
        float scroll = Input.GetAxis ("Mouse ScrollWheel");
        transform.LookAt (target);
        transform.Translate(0, 0, scroll * speed, Space.Self);
    }
    

    【讨论】:

      猜你喜欢
      • 2011-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-28
      相关资源
      最近更新 更多