Hi, I have an enemy with a combo system which goes through a chain of animations. I want to make sure I know when the start/end of the animation is which works perfectly fine with the code below. I then need to make it so that if combo continues I have this script on every animation state with an attack on it. Presumably, the result is it enters the first attack in the chain, evaluates the next state name to see if the tag is “attack” and then by the end decides if should still continue the attack logic. The weird thing is, even if I make a simple node like attack 1 → attack 2 with no exit transition on attack 1 and both states have the script attached, it still reports that the ‘next state’ isnt tagged with “attack”, when it is. How can it not be if there is no alternative? Is there something I’m missing with how NextState works? Are the variables shared between all instances of the class because the base is a scriptable object? A bit confused to be honest.
public class EnemyAttackCheck : StateMachineBehaviour
{
private EnemyCombat _enemyCombat;
private bool _attackChain;
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
_enemyCombat = animator.gameObject.GetComponent<EnemyCombat>();
_enemyCombat.InAttack(true);
if (animator.GetNextAnimatorStateInfo(0).IsTag("attack"))
{
_attackChain = true;
}
else
{
_attackChain = false;
}
}
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (_attackChain == false)
{
Debug.Log("exit attack chain");
_enemyCombat.InAttack(false);
}
}
}