i want to make the object first rotate, wait 3 seconds and then translates foward.
How cain i made the object waits these 3 seconds before perform the translate?
i want to make the object first rotate, wait 3 seconds and then translates foward.
How cain i made the object waits these 3 seconds before perform the translate?
You could use the WaitForSeconds function.
function Start ()
{
transform.Rotate (90, 0, 0);
yield WaitForSeconds (3.0);
transform.Translate (1, 0, 0);
}
thanks a lot
How can I translate the same code in C#? I’m new to coroutines and similar, so I wasn’t able to obtain much working code from the scripting reference. Thanks.
something similar to this should work
void Start ()
{
StartCoroutine( Order() );
}
IEnumerator Order()
{
transform.Rotate (90, 0, 0);
yield return new WaitForSeconds (3.0f);
transform.Translate (1, 0, 0);
}
the main differences are that coroutines must return IEnumerator and that you must have yield return as well as the new there
JS introduces all that stuff behind the scene, so it looks shorter but gives you less control and understanding as well about whats going on.