【发布时间】:2019-02-24 12:45:02
【问题描述】:
我想在拖动鼠标时围绕游戏对象(比如一个立方体)旋转相机,以模拟游戏对象正在旋转的感觉(就像我们在场景编辑器中旋转对象以及在购物网站中一样)。
下面的脚本是我正在使用的脚本。但有时脚本的行为非常奇怪。摄像机沿与预期方向相反的方向旋转。为什么会这样?我需要对代码进行哪些更改才能使其正常工作?请帮忙。
using UnityEngine;
using System.Collections;
public class ExampleBehaviourScript : MonoBehaviour
{
public Camera cameraObj;
public GameObject myGameObj;
public float speed = 2f;
void Update()
{
RotateCamera();
}
void RotateCamera()
{
if(Input.GetMouseButton(0))
{
cameraObj.transform.RotateAround(myGameObj.transform.position,
Vector3.up,
-Input.GetAxis("Mouse X")*speed);
cameraObj.transform.RotateAround(myGameObj.transform.position,
Vector3.right,
-Input.GetAxis("Mouse Y")*speed);
}
}
}
【问题讨论】:
标签: unity3d