滚轮控制视角缩放
public void CameraFOV()
{
float wheel = Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime * 100;
_mainCamera.transform.Translate(Vector3.forward * wheel);
}
左键控制旋转
Update方法中实时获取鼠标水平和竖直方向的偏移量:
float _mouseX = Input.GetAxis(“Mouse X”);
float _mouseY = Input.GetAxis(“Mouse Y”);
-
public void CameraRotate(float _mouseX,float _mouseY) { if (Input.GetMouseButton(0)) { _mainCamera.transform.RotateAround(centerPoint, Vector3.up, _mouseX * rotateSpeed); angle += _mouseY * rotateSpeed; if (angle > maxRotAngle || angle < minRotAngle) { return; } _mainCamera.transform.RotateAround(centerPoint, _mainCamera.transform.right, _mouseY * rotateSpeed); } }
中键控制拖动
-
public void