Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

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,281
    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.