Rotating GameObject 90 degrees

hey guys , im noob at Unity development and i have a silly question. Im trying to rotate a GameObject smoothly at x axis 90 degrees and then stop like a parking lot traffic barrier. Im using this code:

    void Update ()
    {
        rotaciona90 ();
    }

    void rotaciona90 ()
     {
        if (transform.rotation.x < 90)
        {
            transform.Rotate (1, 0, 0);
        }
    }

but this rotate de GameObject forever and dont stop when the x axis exceeds 90, why is that ? Whats the best ad the simpliest methods to do what I want ?

You’re having problems with Euler angles.

You also need to learn to use Time.deltaTime to get the object to rotate smoothly, but that’s not the main thing you’re asking about here.

Thanks ! I’ll take a look at those.

Another option is to use a Tweening Engine like DOTween for simple animations like this. It will make things easier to code and test, especially if you’re just starting.

This is what I’m doing in one of my games to drop a white flag when a villain surrenders. 20 degrees on Y, 40 degrees on Z - 0.2 seconds for the move. Simple.

whiteFlags[topCardIdx].transform.DOLocalRotate(new Vector3(0f, 20f, 40f), 0.2f);

Much easier than playing around in the Update() method and calculating time deltas.

Good thinking ! I will use this as a temporary solution , but im also look to learn about EulerAngles and stuff. Thank you .