Search Unity

Sprite Animations

Discussion in 'Editor & General Support' started by rubble1, Jul 27, 2010.

  1. rubble1

    rubble1

    Joined:
    Apr 25, 2010
    Posts:
    84
    Hi,

    I'm kind of new to unity, so forgive me if this is the wrong place to ask this question. I did this test with a 2D character, but it's not animating quite like I expected it to:

    http://dancoes.net/misc/WebTest/Pig.html

    What I'm doing is scaling each sprite plane to 100% then back to 0% on each frame (maya/FBX doesn't export the visibility animation).

    Why is it that sometimes when the character stops running, there's still a frame from the run cycle being shown?

    Here's my animation code.

    Thanks in advance for any suggestions.


    Code (csharp):
    1.  
    2. function Start (){
    3.  
    4.     animation.wrapMode=WrapMode.Loop;
    5.     animation["run"].layer=-1;
    6.     animation["idle"].layer=-1;
    7.     animation.SyncLayer(-1);
    8.  
    9.     animation["jump"].layer=-10;
    10.     animation["jump"].wrapMode=WrapMode.Once;
    11.     animation.SyncLayer(10);
    12.  
    13.     animation.Stop();
    14.     animation.Play("idle");
    15. }
    16.  
    17.  
    18.  
    19.  
    20. function FixedUpdate (){
    21.  
    22.  
    23.  
    24.  
    25.     if(Input.GetButton("Jump"))
    26.     {
    27.     animation.Play("jump");
    28.     }
    29.    
    30.     if (Input.GetAxis("Horizontal")>.2 || Input.GetAxis("Horizontal")<-.2)
    31.     {
    32.     animation.Play("run");
    33.     }
    34.    
    35.     else
    36.     {
    37.     walkTime=0;
    38.     animation.Play("idle");
    39.     }
    40.    
    41.    
    42.     if (Input.GetKey ("right")) {
    43. transform.localScale.z = 0.176531;
    44. }
    45.  
    46. if (Input.GetKey ("left")) {
    47. transform.localScale.z = -0.176531;
    48. }
    49.    
    50. }
     
  2. KyleStaves

    KyleStaves

    Joined:
    Nov 4, 2009
    Posts:
    821
    Have you tried
    animation.Stop();
    animation.Play("desiredAnimation");
    ?

    animation.Stop() should stop all running animations, and then you play only the desired animation.
     
  3. rubble1

    rubble1

    Joined:
    Apr 25, 2010
    Posts:
    84
    yeah, I tried putting that in different places, and it didn't seem to do anything.

    The animation acutally does stop when you stop pressing the side buttons, but you get a frame from the run cycle appearing over the still.