unity animator trigger parameter code example
Example 1: how to set an animator parameter through the animator unity
public class AnimatorResetBoolAtEnd : StateMachineBehaviour {
[SerializeField]
private string booleanVariableName;
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
animator.SetBool(booleanVariableName, false);
}
}
Example 2: unity check if a animator parameter trigger is activated
bool isPlaying(Animator anim, string stateName)
{
if (anim.GetCurrentAnimatorStateInfo(animLayer).IsName(stateName) &&
anim.GetCurrentAnimatorStateInfo(animLayer).normalizedTime < 1.0f)
return true;
else
return false;
}