26 lines
693 B
C#

using UnityEngine;
public class MouseWheelRotate : MonoBehaviour
{
public float sensitivity = 100.0f; // 鼠标滚轮灵敏度
public float minAngle = -360.0f; // 最小旋转角度
public float maxAngle = 360.0f; // 最大旋转角度
private float xRotation = 0.0f; // 当前X轴旋转角度
void Update()
{
// 检测鼠标滚轮输入
float rotate = -Input.GetAxis("Mouse ScrollWheel") * sensitivity * Time.deltaTime;
// 累积旋转角度
xRotation += rotate;
// 限制旋转角度在指定范围内
xRotation = Mathf.Clamp(xRotation, minAngle, maxAngle);
// 应用旋转到物体上
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
}
}