- Home /
The question is answered, right answer was accepted
How to check if animation is playing? C#
hi all!
i'm having trouble here...
i'm trying to figure out if a specific animation is playing or not in the Animator, and if its not, then do something.
I also am trying to do it from a script that isnt attached to the animated geometry.
this is what I have but I cant get it working:
//in public class Other : MonoBehaviour {
Animator anim;
//in an IEnumerator
if(anim.animator.GetCurrentAnimatorStateInfo(0).IsName("Idle")){
print("IDLE IS PLAYING");
}
//in void Start ()
player = GameObject.Find("Character");
anim = player.GetComponent<Animator>();
can anyone help me with some code that works?
thanks heaps!
:)
Answer by meat5000 · Feb 09, 2015 at 03:39 AM
(anim.animator.Get ETC
Drop the 'animator' and you are on to a winner.
O$$anonymous$$G! meat500!!! You have made my day!! That has been plaguing me for days!! Thank you so much!!! :D
You are welcome.
Just like using 'gameObject' to reference the actual gameobject the script is on, using 'animator' references the Animator on the gameobject. When using the words this way, the editor does the linking for you so you don't need to include the declarations; it's done behind the scenes.
You provided your own reference (good practise)
Animator anim
and linked it with GetComponent.
So you only need to use what you have defined :
anim.GetCurrentAnimatorStateInfo(0)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Conflicting Animator SetTrigger 0 Answers
How to check if an object is rendered? 2 Answers
Distribute terrain in zones 3 Answers