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);
}
}

最新更新