- Home /
 
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! 
Answer by NeverHopeless · Jul 02, 2015 at 05:47 AM
As I see you have two more options:
Animator Component
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);
 
              Ok so right now I installed and imported LeanTween and my code looks like:
 void Start()
 {
     InvokeRepeating ("RotateZ", 0.1f, 3);
 }
 void RotateZ() {
     LeanTween.rotateZ(this.gameObject, -60.0, 0.5f);
 }
 
                  }
But I'm currently getting two errors:
1.) The best overloaded match for 'LeanTween.rotateZ(UnityEngine.GameObject,float, float)' has some invalid arguments 2.)Argument '#2' cannot convert double expression to type 'float' 
InvokeRepeating ("RotateZ", 0.1f, 3f); Here just 3 means 3(double) you need to specify it be considered as float using 3f. 
Your answer