我正在尝试限制玩家相机,这样相机就无法 360 度旋转。 这就是我想要做的,但由于某种原因,当 newRorationX 达到 0 时,它会限制到他的最大值; 当 newRorationX 的值达到 80 时,他就达到最大值并阻止玩家继续向下看(正确的行为)。但当他开始向上看时 - newRorationX 达到 0,它又回到 80 并且玩家向下看。
我做错了什么?
private void RotateBodyWithMouse()
{
if (Input.GetMouseButton(1))
{
Vector2 mouseInput = new Vector2(Input.GetAxisRaw("Mouse X"), -Input.GetAxisRaw("Mouse Y"));
transform.Rotate(Vector3.up * mouseInput.x * _mouseSensitivity.x * Time.deltaTime);
float newRotationX = _currentCamera.transform.rotation.eulerAngles.x + (mouseInput.y * _mouseSensitivity.y * Time.deltaTime);
newRotationX = Mathf.Clamp(newRotationX, -80, 80);
_currentCamera.transform.rotation = Quaternion.Euler(newRotationX, _currentCamera.transform.rotation.eulerAngles.y, _currentCamera.transform.rotation.eulerAngles.z);
}
}
您需要有两个独立的游戏对象进行旋转。使用一个游戏对象作为 y 轴,并将所有旋转设置为 0。对另一个游戏对象执行相同的操作,并将其嵌套在另一个游戏对象内。