playMaker

Author Topic: GetCurrentAnimation  (Read 3630 times)

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • blog
GetCurrentAnimation
« on: August 01, 2011, 09:37:02 PM »
something that may help when you want to stop an animation but do not know which one is actually playing.

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;
[ActionCategory(ActionCategory.Animation)]
[Tooltip("Get the current animation name and store it in a string variable")]
public class GetCurrentAnimation : FsmStateAction
{

[RequiredField]
[CheckForComponent(typeof(Animation))]
[Tooltip("A Game Object with an Animation Component.")]
public FsmOwnerDefault gameObject;

[RequiredField]
[UIHint(UIHint.Variable)]
public FsmString storedString;

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

public override void OnEnter()
{
DoGetCurrentAnimation();
Finish();
}

void DoGetCurrentAnimation()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if(go == null)
       return;

if(go.animation.isPlaying)
storedString.Value = go.animation.clip.name;
}
}

rollingdjs

  • Playmaker Newbie
  • *
  • Posts: 8
Re: GetCurrentAnimation
« Reply #1 on: September 02, 2012, 01:52:57 AM »
The string seems to stay on the first animation played. Is there any way to get the string to change as the animation changes?