Question by
timyboy12345 · Feb 24, 2016 at 08:21 PM ·
waitforsecondsyield waitforseconds
Wait for a certain amount of time
Hi there, I'm kind of noob with Unity, but trying to learn. I'm using JavaScript mostly. I want to wait a certain amount of time, so I can start something, and wait 10 seconds or so, and then execute something else:
function startRotate ()
{ speed = 100f; yield WaitForSeconds(2); speed = 0f;
}
But the 'yield' gives me an error 'ArgumentException: method return type is incompatible' so how can I fix this?
Comment
Best Answer
Answer by hexagonius · Feb 24, 2016 at 08:54 PM
startRotate needs return type IEnumerator. Call the function via StartCoroutine(startRotate());
Answer by timyboy12345 · Feb 24, 2016 at 09:36 PM
Owh, that actually worked :D, thanks dude! ( @hexagonius )
function startRotate () {
speed = 100f;
yield WaitForSeconds(2);
speed = 0f;
}
function Startcour () {
StartCoroutine(startRotate());
Debug.Log ("Starten!");
}