帮我写个unity 鼠标拖动控制主相机移动的脚本
时间: 2023-09-23 21:12:22 浏览: 102
好的,以下是一个简单的Unity鼠标拖动控制主相机移动的脚本:
```
using UnityEngine;
public class CameraController : MonoBehaviour
{
public float sensitivity = 100.0f;
public float maxYAngle = 80.0f;
private Vector2 currentRotation;
void Update()
{
if (Input.GetMouseButton(0))
{
currentRotation.x += Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
currentRotation.y -= Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
currentRotation.y = Mathf.Clamp(currentRotation.y, -maxYAngle, maxYAngle);
transform.rotation = Quaternion.Euler(currentRotation.y, currentRotation.x, 0);
}
}
}
```
你可以在你的主相机上添加这个脚本,它将使你能够通过鼠标拖动主相机进行移动。
阅读全文