2015年5月13日水曜日

How to know what animation is playing at Unity script

Do you have ever being in trouble when you using Animator in Unity?
I have.
I want to know what is playing now from script and it was little bit hard to find.

I was using C# and Unity4.5

In Animator class there is GetCurrentAnimatorStateInfo(0).IsName.
And It is the method to get the playing animation name.

It will write like this!

Animator UnityChanAnimation;
public GameObject UnityChan;

void Start () {
    UnityChanAnimation = UnityChan.GetComponent<Animator> ();
}

void Update () {
  if(UnityChanAnimation.GetCurrentAnimatorStateInfo(0).IsName("dance")) == true){
  //playing
  }
}

if dance motion is playing, the it will return true!!

0 件のコメント:

コメントを投稿