Unity - Scripting API: AnimatorStateInfo.IsTag
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Submission failed
For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Declaration
public bool IsTag(string tag);
Parameters
| Parameter | Description |
|---|---|
| tag | The tag to check. |
Returns
bool True if the animation state has the specified tag, false otherwise.
Description
Checks whether the animation state has the specified tag.
// This script demonstrates how to check if the current state of an Animator is tagged with a specific tag. using UnityEngine; [RequireComponent(typeof(Animator))] public class AnimatorStateInfoIsTagExample : MonoBehaviour { // The tag to check for. public string tagName = "Jump"; // The Animator component on the GameObject this script is attached to. Animator m_Animator; void Start() { m_Animator = GetComponent<Animator>(); } void Update() { // If the current state is tagged with the specified tag, log a message. var stateInfo = m_Animator.GetCurrentAnimatorStateInfo(0); if (stateInfo.IsTag(tagName)) { Debug.Log($"Current state is tagged as {tagName}"); } } }