How to set an animator machine state as running?

Updated 3 days ago in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on October 9, 2017

I am trying to set the localPosition to a new Vector3 when the animator has “Slide” animation playing but how to access the animator state info to check if it is running or not?

public Animator anim;
 // Use this for initialization
 void Start ()
{
anim = GetComponent<Animator> ();
 }
 // Update is called once per frame
 void Update ()
{
 if (GameManager.instance.currentGameState == GameState.inGame) {
 if (/*I want to check animator state info here, to be specific"Slide" animation state*/) 
 {
this.transform.localPosition = new Vector3 (0f, 2.4f, 0f);
 }
 }
}
  • Liked by
Reply
2 on October 9, 2017

Thanks, I got this one

if (GameManager.instance.currentGameState == GameState.inGame) {
 if (anim.GetCurrentAnimatorStateInfo (0).IsName ("Slide 1")) {
 this.transform.localPosition = new Vector3 (0f, 2.4f, 0f);
 }
 else 
 {
 this.transform.localPosition = new Vector3 (0f, 3f, 0f);
 }

 

This just did the thing.

Helpful
on October 9, 2017

Very well. So this one can be closed?

 

3 days ago

Yes.

Show more replies
  • Liked by
Reply
Cancel