- Home /
How to check if Animator is playing
How can I check if my Animation is playing in my Animator
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Indingo_Lava_Burst_Activator_Deactivator : MonoBehaviour {
private PolygonCollider2D myPolygonCollider2D;
private Animator myAnimator;
private bool lava_burst;
private Rigidbody2D MyRigidbody;
private Indingo_Movement indingoMovement;
private Indingo_Jump_01 indingoJump01;
private Indingo_Jump_02 indingoJump02;
// Use this for initialization
void Start()
{
myPolygonCollider2D = GetComponent<PolygonCollider2D>();
myPolygonCollider2D.enabled = false;
myAnimator = GetComponent<Animator>();
MyRigidbody = GetComponent<Rigidbody2D>();
indingoMovement = GetComponent<Indingo_Movement>();
indingoJump01 = GetComponent<Indingo_Jump_01>();
indingoJump02 = GetComponent<Indingo_Jump_02>();
}
// Update is called once per frame
void FixedUpdate()
{
if (Input.GetKey(KeyCode.G))
{
myAnimator.SetBool("lava_burst", true);
myPolygonCollider2D.enabled = true;
indingoMovement.enabled = false;
indingoJump01.enabled = false;
indingoJump02.enabled = false;
}
else
{
myAnimator.SetBool("lava_burst", false);
myPolygonCollider2D.enabled = false;
indingoMovement.enabled = true;
indingoJump01.enabled = true;
indingoJump02.enabled = true;
}
if (MyRigidbody.velocity != Vector2.zero)
{
myPolygonCollider2D.enabled = false;
Debug.Log ("Player Is Moving");
}
}
}
Answer by GlitchCrew · Sep 06, 2017 at 04:04 AM
If you want to get certain information about the animator from code, you need to use AnimatorStateInfo struct. Check the documentation:
https://docs.unity3d.com/ScriptReference/AnimatorStateInfo.html
Or just use GetCurrentAnimatorStateInfo() on your animator.
I think that you will need to do something with normalizedTime of the current state but I'm not sure because that really depends on your specific problem.
Answer by Akusan · Sep 06, 2017 at 03:37 AM
You can check if your animation is playing by running your game then selecting your character with animation and you will see a blue bar underneath the current animation it is running
On script, you can use:
GetCurrentAnimatorStateInfo()
Answer by Tekksin · Jun 28, 2018 at 07:29 AM
string animName;
string animName2 = this.anim.GetCurrentAnimatorClipInfo (0) [0].clip.name;
while (animName == animName2) {
if (anim.GetCurrentAnimatorClipInfo (0).Length != 0) {
animName = this.anim.GetCurrentAnimatorClipInfo (0) [0].clip.name;
print ("playing " + animName);
} else {
print ("sometimes the array index doesn't have anything. this avoids errors)";
}
yield return null;
}
print("The new anim that's playing is: " + animName);
I've searched the internet up and down, and haven't seen this kinda check. Lets you know AS SOON AS an animator clip finishes. And it averts unity's pesky little errors.
Your answer
![](https://koobas.hobune.stream/wayback/20220612134258im_/https://answers.unity.com/themes/thub/images/avi.jpg)