0
\$\begingroup\$

How can I play animation with the help of the animator once, wait until it ends playing and continue script code?

I am playing an animation with the help of the animator this way:

animator.SetBool(what, toAnimate);
  1. I am starting my animation in that way:

    rabit.animate("die", true);

  2. I am making a transition to another animation this way:

    rabit.animate("die", false);

I need to wait after step 1. before making step 2. so that animation plays. How can I do that?

\$\endgroup\$
  • \$\begingroup\$ You may not need a script for this. Can you show your animator and the parameters ? I think you can use a trigger parameter instead of a boolean, and use auto-transition from your "die" state to your other state. \$\endgroup\$ – Hellium May 26 '17 at 7:06
0
\$\begingroup\$

You can use AnimationEvent. It will besically give you an opportunity to call a function in the end of your animation. More on that here here.

\$\endgroup\$
2
\$\begingroup\$

You can call a coroutine:

In C#:

IEnumerator PlayWaitPlay(){
      rabit.animate("die", true);
      yield return new WaitForSeconds(3); // your animation time
      rabit.animate("die", false);
}

To call it use

StartCoroutine(PlayWaitPlay());

Hope it helps :)

\$\endgroup\$
  • \$\begingroup\$ How can I get the time of my animation from animator? \$\endgroup\$ – Yaroslav May 26 '17 at 18:17
  • \$\begingroup\$ And your solution does not work. \$\endgroup\$ – Yaroslav May 26 '17 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.