我正在尝试简化产品可视化。我想缩放或移动相机朝向物体。我的代码如下所示:
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);
}
}
}
但是当我尝试缩放时,它只是“飞”&#34;在物体周围,当相机进入物体的另一侧时,它开始后退。
答案 0 :(得分:1)
这是因为你使用Space.World而不是Space.Self:
void Update ()
{
float scroll = Input.GetAxis ("Mouse ScrollWheel");
transform.LookAt (target);
transform.Translate(0, 0, scroll * speed, Space.Self);
}