Rotate to an amount, wait, rotate to an amount

I’m making an obstacle course and I need a platform to rotate along the Z axis to 60 degrees, wait 3 seconds, rotate to -60 degrees and then loop. I’m really new to unity, this is my first project and I’ve been stuck on this for a while. I thought of using an if statement but I don’t know how to correctly set it up, something that would be like:

Continue to increase z axis rotation by 1
If z axis rotation = 60
Wait 3 seconds
Start to decrease rotation by 1
If z axis rotation = -60
Loop

But I have no idea how to go about doing this. I also tried using Coroutines for the wait but that just messed up the code more. If someone could show me how to get this to work it would help me a ton
Thanks!

As I see you have two more options:

  1. Animator Component
  2. LeanTween plugin.

With first option you can define two state animation Rotate and Stop. Use InvokeReperating to toggle the states every 3 seconds. e.g.,

GetComponent<Animator>().SetInt("yourStateVariable", yourStateNumber);

With second option you can use:

void RotateZ() {
    LeanTween.rotateZ(this.gameObject, -60.0, 0.5f);
}

and use InvokeRepeating to schedule this function for every 3 seconds. e.g.,

InvokeRepeating("RotateZ", 0.1f, 3.0f);