Unity Community


Results 1 to 9 of 9

  1. Posts
    54

    Play animation sequence

    Hi,
    I have 3 animation A,B,C.
    I want to play animation A then B then C. When animation C is completed, I will show a notice.
    How can I do that? I don't know how to callback when animation complete .

    Thanks so much.


  2. Location
    Philippines
    Posts
    1,020
    Use CrossFadeQueued() so the animations will play one after the other. To check if an animation has finished playing, store the AnimationState in a temporary variable:

    Note: I am using C#

    Add this as a member variable to your class:
    Code:  

    Put this in Start() (change nameOfAnimation to the actual animation name):
    Code:  
    1. anim = animation["nameOfAnimation"];

    Then put this in Update():
    Code:  
    1. if (anim.normalizedTime == 1.0f)
    2. {
    3.   // animation is finished. do something here
    4. }

    I have not tested this code so tell me if there's anything wrong.
    Unity Philippines Users Group: Working somewhere in Metro Manila? Hang out with us!
    My Unity Build Report Plugin: Track down file size bloat in your builds!
    Project Victis: My personal project, a tactical turn-based RPG
    Personal Dev Blog: Where I post my game design rants & share some useful code


  3. Posts
    54
    It is not work. Because normalize time is checked before animation complete.


  4. Location
    Brisbane,Australia
    Posts
    210
    You can use animation.Crossfade( ) function.


  5. Posts
    54
    Code:  
    1. void Update()
    2. {
    3.      animation.CrossFade("attack");
    4.    
    5.      if (anim.normalizedTime == 1.0f)
    6.      {
    7.           //  do something..
    8.      }
    9.  
    10. }

    The code in do something is not work


  6. Posts
    54


  7. Location
    Philippines
    Posts
    1,020
    Again, I said use CrossFadeQueued, not CrossFade, so that they will be played one after the other.

    Code:  
    1.  
    2. void Start()
    3. {
    4.   animation.CrossFadeQueued("animation1");
    5.   animation.CrossFadeQueued("animation2");
    6.   animation.CrossFadeQueued("animation3");
    7.   anim = animation["animation3"];
    8. }
    9.  
    10. void Update()
    11. {
    12.   if (anim.normalizedTime == 1.0f)
    13.   {
    14.     Debug.Log("animation3 is finished");
    15.   }
    16. }

    nomalizedTime starts at 0.0 at the beginning, 0.5 at the middle of the animation, and will become 1.0 when the animation is finished.
    Unity Philippines Users Group: Working somewhere in Metro Manila? Hang out with us!
    My Unity Build Report Plugin: Track down file size bloat in your builds!
    Project Victis: My personal project, a tactical turn-based RPG
    Personal Dev Blog: Where I post my game design rants & share some useful code


  8. Posts
    54
    Thanks.
    I want to play animation in a function , not on Start()
    Example when I click a button, animaton sequence start, then show a notice when complete


  9. Location
    Philippines
    Posts
    1,020
    Quote Originally Posted by kagura View Post
    Thanks.
    I want to play animation in a function , not on Start()
    Example when I click a button, animaton sequence start, then show a notice when complete
    Then put the code that plays the animation in a different function then call that function when you need it to.
    Unity Philippines Users Group: Working somewhere in Metro Manila? Hang out with us!
    My Unity Build Report Plugin: Track down file size bloat in your builds!
    Project Victis: My personal project, a tactical turn-based RPG
    Personal Dev Blog: Where I post my game design rants & share some useful code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •