Hi everyone!
When I try to attack in a combo, I run into a problem. Only the first animation is played.
PlayerAttackingState.cs
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAttackingState : PlayerBaseState
{
private float previousFrameTime;
private Attack attack;
public PlayerAttackingState(PlayerStateMachine stateMachine, int attackIndex) : base(stateMachine)
{
attack = stateMachine.Attacks[attackIndex];
}
public override void Enter()
{
stateMachine.Animator.CrossFadeInFixedTime(attack.AnimationName, attack.TransitionDuration);
}
public override void Tick(float deltaTime)
{
Move(deltaTime);
FaceTarget();
float normalizedTime = GetNormalizedTime();
if (normalizedTime > previousFrameTime && normalizedTime < 1f)
{
if (stateMachine.InputReader.IsAttacking)
{
TryComboAttack(normalizedTime);
}
}
else
{
// go back to locotmotion
}
previousFrameTime = normalizedTime;
}
public override void Exit()
{
}
private void TryComboAttack(float normalizedTime)
{
if (attack.ComboStateIndex == -1) { return; }
if (normalizedTime < attack.ComboAttackTime) { return; }
stateMachine.SwitchState
(
new PlayerAttackingState
(
stateMachine,
attack.ComboStateIndex
)
);
}
private float GetNormalizedTime()
{
AnimatorStateInfo currentInfo = stateMachine.Animator.GetCurrentAnimatorStateInfo(0);
AnimatorStateInfo nextInfo = stateMachine.Animator.GetNextAnimatorStateInfo(0);
if (stateMachine.Animator.IsInTransition(0) && nextInfo.IsTag("Attack"))
{
return nextInfo.normalizedTime;
}
else if (!stateMachine.Animator.IsInTransition(0) && currentInfo.IsTag("Attack"))
{
return currentInfo.normalizedTime;
}
else
{
return 0f;
}
}
}
I’m pretty sure the codes are the same. What could be causing this issue?