EularAngels Question / Lock a Rotation?

So I have this script, and there’s this part of rotation :

        //ROTATION
        if (Input.GetKey(KeyCode.UpArrow))
        {//rotate up by 10
            gameObject.transform.Rotate(-10f, 0, 0);
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {//rotate Left by 10
            gameObject.transform.Rotate(0, 0, -10f);
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {//rotate Right by 10
            gameObject.transform.Rotate(0, 0, 10f);
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {//rotate Down by 10
            gameObject.transform.Rotate(10f, 0, 0);
        }

Now I am wondering, Is there any way to restrict it so it doesn’t go past a certain degree. I know it’s called EulerAngels

But I don’t know how to implement it into this, Do I do it in separate Parenthesis?

Thanks in advance

You have to store intermediate values to limit them, something in the like of :

private float xMin = -30;
private float xMax = 30;
void Update ()
{
//ROTATION
         if (Input.GetKey(KeyCode.UpArrow))
         {
            float x = 10f;
             if ((gameObject.transform.eulerAngles.x + x) < xMin)
                 x = xMin - gameObject.transform.eulerAngles.x;
             else if ((gameObject.transform.eulerAngles.x + x) > xMax)
                 x = xMax - gameObject.transform.eulerAngles.x;

             gameObject.transform.Rotate(x, 0, 0);
         }
}

Though, rotations are tricky if you want to do this on all three axes.