unity clamp object rotation code example

Example 1: unity clamp rotation

float rotationX = 0;
float rotationY = 0;
// you might also have some rotation speed variable
void Update() {
   rotationX += Input.GetAxis("Vertical") * Time.deltaTime;
   rotationX = Mathf.Clamp(rotationX, minRotationX, maxRotationX);
   rotationY += Input.GetAxis("Horizontal" * Time.deltaTime;
   transform.rotation = Quaternion.Euler(rotationX, rotationY, 0);
 }

Example 2: how to get rotation of object in unity c#

float angleX = myTransformGO.rotation.eulerAngles.x;  
float angleY = myTransformGO.rotation.eulerAngles.y; 
float angleZ = myTransformGO.rotation.eulerAngles.z;