unity3d摄像机镜头移动
时间: 2023-07-29 07:14:56 浏览: 207
您可以使用以下代码在Unity中移动摄像机镜头:
```
public class CameraController : MonoBehaviour
{
public float speed = 10.0f; // 镜头移动速度
public float sensitivity = 0.1f; // 鼠标灵敏度
private float mouseX = 0.0f;
private float mouseY = 0.0f;
void Update()
{
float horizontal = Input.GetAxis("Horizontal"); // 获取水平移动输入
float vertical = Input.GetAxis("Vertical"); // 获取垂直移动输入
transform.Translate(new Vector3(horizontal, 0, vertical) * speed * Time.deltaTime); // 移动摄像机
mouseX += Input.GetAxis("Mouse X") * sensitivity; // 获取鼠标移动输入
mouseY += Input.GetAxis("Mouse Y") * sensitivity;
transform.eulerAngles = new Vector3(-mouseY, mouseX, 0); // 旋转摄像机
}
}
```
在此示例中,我们使用Input.GetAxis方法获取水平和垂直移动输入,然后使用Transform.Translate方法移动摄像机。我们还使用Input.GetAxis方法获取鼠标移动输入,并使用Transform.eulerAngles方法旋转摄像机。您可以根据需要调整速度和灵敏度。
阅读全文
相关推荐

















