Search Unity

How to tell in script if an animation has stopped playing? :)

Discussion in 'Scripting' started by Rutenis, Sep 17, 2014.

  1. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297
    Hey, so i was wondering, how do i tell in a script that the animation has finished?

    -Thanks!! :)))
     
  2. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    Code (CSharp):
    1. if (!animation.IsPlaying("animation name"))
    2.             //Do stuff
     
  3. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    that might not always be what you want. For more precise detection. Do something like:

    Code (CSharp):
    1.  
    2. IEnumerator WaitForAnimation (Animation animation) {
    3.     do {
    4.         yield return null;
    5.     } while (animation.isPlaying);
    6. }