Rotate 90 Degrees and Pause

Hi,
I’m trying to keep rotating an object 90 degrees then pause the rotation for a few seconds, I used eulerAngles but my script stops working when the eulerAngles goes from 350 degrees to 0.
Any ideas how to work around this?
Thank you

public class RotatePause : MonoBehaviour
{
    // Rotation speed & axis
    public int speed = 100;
    public int dir = 1;
    float lastRotation;
    bool canRotate;


    float yRotation = 0;
    void Start()
    {
        lastRotation = transform.rotation.eulerAngles.y;
        canRotate = true;
    }

    void Update()
    {
        if (canRotate)
        {
            yRotation += Time.deltaTime * speed;
            transform.rotation = Quaternion.Euler(0, yRotation, 0);
            if (transform.rotation.eulerAngles.y > lastRotation + 90 )
            {
                canRotate = false;
                transform.eulerAngles = new Vector3(0, lastRotation + 90, 0);
                StartCoroutine("PauseRotation");
                lastRotation = transform.rotation.eulerAngles.y;
            }
        }
    }

    IEnumerator PauseRotation()
    {
        yield return new WaitForSeconds(2.5f);
        canRotate = true;
    }

}

Line 23 above… you cannot read eulerAngles out of a quaternion reliably. This is because internally it does not use them and instead attempts to regenerate them. Due to the gimbal lock problem, this regenerated number is not reliable once you go past 90 degrees.

Instead keep your own angle variable, change it, and use it to drive the rotation with:

transform.localRotation = Quaternion.Euler( 0, angle, 0);

I’ve been having the same issue when working on my Tetris game. I wrote the code, and it still had the same error. Any fix?

You necroed the thread to reply to a post that already describes the fix, to ask for a fix?