C# How do I place limits on the x rotation and reset the x rotation to 360?

In my game, I use the vertical direction arrows to rotate my object up and down. First, I want to restrict the range from 360 to 310 degrees (as I’m seeing them in the Inspector). The idea I had was to use an if statement, but I don’t know how to reference the x rotation of my object. My code would look something like this:

if (transform.x > 310) {do the action I want;}

Second, my object jumps at the x angle, but lands with the same x angle. I want to reset ONLY the x angle to 360 to level it out on landing, but leave the y and z as they are. How can I change only the x rotation? transform.rotation = Quaternion.identity doesn’t work for me because the y rotation is also reset.

Thank you for your help.

BTW, the prototype I’m working on is for a Capture the Flag game. If anyone wants to collaborate, just reply.

Instead of using an if statement to clamp the rotation, you could instead do something like:

xRotation = Mathf.Clamp(xRotation, 310, 360);

As for setting only the x rotation in a quaternion, you can do:

Quaternion current = transform.rotation;

transform.rotation = Mathf.Clamp(current.eulerAngles.x, 310, 360);

Quaternion final = Quaternion.Euler(clamped, current.eulerAngles.y, current.eulerAngles.z);