Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - AnnaM

Pages: [1]
1
EDIT - I've just gone back to Unity and this is now working with a 1 frame animation (must've not committed something!) although still not the ping pong - editing the question accordingly.

I've created a small script to run through an animation when a UIItem is pressed which should then switch back to the object's default animation.

It works fine when the touch animation is set to Once, and has multiple frames. But does not work if the touch animation    is set to PingPong.  It continues to run the touch animation forever and never goes back to the default.

Should .AnimationCompleted work here, or should I use other methods to handle these cases?
I have pasted my script below for reference.

Thanks!

public tk2dSprite animatedSprite;
   public string myTouchAnim;
   public string myDefaultAnim;
   public bool singleAnim;

   tk2dSpriteAnimator spriteAnimation;

   void Start () {
      spriteAnimation = animatedSprite.GetComponent<tk2dSpriteAnimator>();
   }

   void ReturnToDefaultAnim (tk2dSpriteAnimator sprite, tk2dSpriteAnimationClip clip){
      spriteAnimation.Play (myDefaultAnim);
   }

   void ButtonDown () {
      if (!spriteAnimation.IsPlaying(myTouchAnim)) {
         spriteAnimation.Play(myTouchAnim);
         spriteAnimation.AnimationCompleted=ReturnToDefaultAnim;
      }
}

Pages: [1]