Search Unity

Playing the animation forward and reverse using animator

Discussion in 'Animation' started by schetty, Dec 23, 2014.

  1. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    Hi Everyone,


    I am creating the sprite animation in project, in this sprite animation i am applying on the 3D environment. It has totally 50 sprites, i have done the sprite animation. The problem is i want to reverse this animation like key frames should play from the 50 to 1.

    This function available on the animation function, if we give speed as -1 it will play the reverse direction i have dont that too, but i cannot find it on animator. And if i use the animation the i cannot see the sprite in my scene.

    So please help me to get rid of this problem.


    Thanks.
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,698
    Each state in the animator controller has a Speed field. Click on the state's node on the Animator canvas and set Speed to -1.

    If you want to play the animation forward and reverse, make two states. On one, set Speed to 1. On the other, set Speed to -1.
     
    EvilGremlin and samurai926 like this.
  3. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    i have used the below code:

    Code (csharp):
    1.  
    2. if(GUI.Button(Rect(0, 0, 100, 30), "2D Anim"))
    3. {
    4.  
    5. //play forward
    6. anim.speed = 1;
    7. anim.SetBool("2danim", true);
    8. }
    9.  
    10.  
    11. if(GUI.Button(Rect(100, 0, 100, 30), "2D Anim"))
    12. {
    13.  
    14. //play reverse
    15. anim.speed = -1;
    16. anim.SetBool("2danim", false);
    17.  
    18. }
    19.  
    20.          
    21.  
    its working it seems... But after i played the reverse animation if i make the boolean true its taking the long time to play..
     
  4. schetty

    schetty

    Joined:
    Jul 23, 2012
    Posts:
    424
    here anim notice the animator of the gameobject.