playMaker

Author Topic: 2D Toolkit Play() Animation  (Read 5307 times)

rocket5

  • Playmaker Newbie
  • *
  • Posts: 4
    • Rocket 5 Studios
2D Toolkit Play() Animation
« on: August 28, 2011, 08:43:21 PM »
Here's an Action that will play an animation on a 2D Toolkit Animated Sprite (tk2dAnimatedSprite).  This is my first Action so I don't know yet if there's a better way to do this, but it works!  -Tim

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("2D Toolkit")]
[Tooltip("Plays a sprite animation on a tk2dAnimatedSprite")]
public class PlayAnim : FsmStateAction {
[RequiredField]
public FsmOwnerDefault gameObject;
public FsmString clipName;

private GameObject go;
private tk2dAnimatedSprite spriteAnim;

public override void Reset() {
gameObject = null;
clipName = null;
}

public override void OnEnter() {
go = gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value;
spriteAnim = go.GetComponent<tk2dAnimatedSprite>();
spriteAnim.Play(clipName.Value);
Finish();
}
}
}

midnight_stories

  • Playmaker Newbie
  • *
  • Posts: 3
Re: 2D Toolkit Play() Animation
« Reply #1 on: December 15, 2012, 08:53:34 AM »
This way better than the normal play animation at least it changes the animation back and forwards.
Thanks this is a huge help !!!