help with yield function

Hey I want to use the 'wait' function so that I can freeze my animation for some interval of time. I want to use this 'wait' function as an Event in my animation but it doesnt work.

function wait () { yield WaitForSeconds(5.0); //WaitForSeconds (5); }

why not?

2 Answers

2

You probably call it like this:

wait(); // Starts a new coroutine, and continues immediately.

But you need to yield to whatever it yields, like this:

yield wait();  // Starts a new coroutine, and continues when coroutine is done.

you can't use yield WaitForSeconds as an event to freeze your animation WaitForSeconds suspends the execution of your code only .

Yeah, you'd have to set the speed for the animation state to 0, wait, then set the speed back to whatever it was before (usually 1)

if you want to freeze your animation try this method: 1-split your animation in two (one before where you want to freeze and one after ) 2-call your animations and use wait between them gameObject.animation.Play("first animation"); yield WaitForSeconds (5); gameObject.animation.Play("second animation"); This worked good for me Ps:the animation that i used were imported from maya