Rotating object and stopping the rotation again. C#

Hey, I want to rotate an object to a sertant value, but I can’t make the rotation stop again. So when it has rotated to the value of 30 on the y rotation I want it to stop again. The method I’m using to rotate looks like this:

void RotateObject()
    if (transform.rotation.y <= 30f)
        transform.Rotate(0f, 0f, 1f, Space.Self);
    else if (transform.rotation.y >= 30f)
        transform.Rotate(0f, 0f, 0f, Space.Self);


Can’t figure out why it isn’t stopping again.
Thanks in advance

It's because transform.rotation isn't stored as an 'xyz euler' rotation representation- it's a quaternion, and it basically doesn't work the way you think it does. Try using


instead, since it's more like what you are used to.

Of course, I'm pretty sure there are much better ways of rotating an object over time. For example, this code isn't frame-rate independent, so the speed of rotation will change as the framerate increases and decreases. But that's not the topic of your question, so I won't get into that.

Sounds right, but can’t really figure out how that transform.rotation.eulerAngles work, can you give an eksampel?