Mathf.Clamp 在达到 maxValue 时将我的 eulerangle 重置为 minValue,而不是将其限制在 maxValue。我试过这个:
rotateX = Input.GetAxis("Mouse X") * senseX;
player.transform.Rotate(player.up, Mathf.Deg2Rad * rotateX, Space.World);
playerXRotation = player.eulerAngles;
while (playerXRotation.y > 180f)
playerXRotation.y -= 360f;
Debug.Log("Y Rotation: " + playerXRotation.y);
playerXRotation.y = Mathf.Clamp(playerXRotation.y, lowLimitY, highLimitY);
player.transform.eulerAngles = playerXRotation;
和这个 :
rotate = Input.GetAxis("Mouse X") * senseX;
rotation = player.transform.eulerAngles;
rotation.y += rotate * RateOfRotate;
while (rotation.y > 180)
{
rotation.y -= 360;
}
rotation.y = Mathf.Clamp(rotation.y, lowLimitY, highLimitY);
player.transform.eulerAngles = rotation;
在这两种情况下,我的 lowLimitY = 0 和 highLimitY = 180;我被困在这个问题上,不知道如何解决它。任何帮助将不胜感激。