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\$
1
  • \$\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
    Commented May 26, 2017 at 7:06

2 Answers 2

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\$
2
  • \$\begingroup\$ How can I get the time of my animation from animator? \$\endgroup\$
    – Yaroslav
    Commented May 26, 2017 at 18:17
  • \$\begingroup\$ And your solution does not work. \$\endgroup\$
    – Yaroslav
    Commented May 26, 2017 at 19:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .