c# - Unity中的夹具旋转问题
问题描述
我试图限制我的 x 轴旋转,但它根本不夹紧。就像没有效果一样。我究竟做错了什么?
public float speed = 5f;
public float minRotation = -45;
public float maxRotation = 10;
void Update()
{
if (Input.GetMouseButton(0))
{
float xaxisRotation = Input.GetAxis("Mouse Y") * speed;
xaxisRotation = Mathf.Clamp(xaxisRotation, minRotation, maxRotation);
transform.Rotate(Vector3.right, xaxisRotation);
}
}
解决方案
您钳制每帧应用的最大旋转。因此,如果您想钳制旋转本身,则必须钳制总旋转。
尝试:
public float speed = 5f;
public float minRotation = -45;
public float maxRotation = 10;
void Update()
{
if (Input.GetMouseButton(0))
{
float xaxisRotation = Input.GetAxis("Mouse Y") * speed;
transform.Rotate(Vector3.right, xaxisRotation);
transform.y = Mathf.Clamp(transform.eulerAngles.y, minRotation, maxRotation);
}
}
推荐阅读
- javascript - 每当字段等于一定长度时如何调用JS函数?
- javascript - 我将如何设置 HTML 页面以在每一天都有一个新标题?
- objective-c - 无法使用 [[context executeRequest:fetchRequest error:nil] mutableCopy] 获取结果;
- c# - VSTO C# Excel 修改并保存 xltx 文件
- c# - 由于我的集合长度,MessageBox 错误显示 6 次,但我希望每次用户输入错误的登录信息时它显示 1 次
- git - 如何正确切换到分叉存储库?
- python - PyQt5:将信号从工作线程连接到 MainWindow
- python - Django rest 框架 - 优化嵌套相关字段的序列化
- google-apps-script - Google Apps 脚本文档模板权限问题
- aws-lambda - 针对失败 lambda 的自定义 AWS SNS 通知