Combo System In Unity

This is my attacking state but i want to use click attack 1, click attack 2, etc, but i dont know where to start.
Im using only events to attack in the input reader:

public event Action AttackEvent;
public void OnAttack(InputAction.CallbackContext context)

    {

        if(!context.performed){return;}

        AttackEvent?.Invoke();

    }
public class PlayerAttackingState : PlayerBaseState

{

    private float previusFrameTime;

    private Attack attack;

    public PlayerAttackingState(PlayerStateMachine stateMachine, int attackkIndex) : base(stateMachine)

    {

        attack = stateMachine.Attacks[attackkIndex];

    }

    public override void Enter()

    {

        stateMachine.Animator.CrossFadeInFixedTime(attack.AnimationName, attack.TransitionDuration);

    }

    public override void Tick(float deltaTime)

    {

        Move(deltaTime);

        FaceTarget();

        float normalizedTime = GetNormalizedTime();

        previusFrameTime = normalizedTime;

    }

    public override void Exit()

    {

       

    }

    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 0;

        }

    }

    private void TryComboAttack(float normalizedTime)

    {

        if(attack.ComboStateIndex == -1){return;}

        if(normalizedTime < attack.ComboAttackTime){return;}

        stateMachine.SwitchState

        (

            new PlayerAttackingState

            (

                stateMachine,

                attack.ComboStateIndex

            )

        );

    }

}

You may wish to review the lecture Combo Attacks in the Third Person course.

Nathan covers setting up combo attacks. With the code you have right now, you’re getting the Normalized Time, but you’re not using it to check the timing of the next attack (or even switching out of the Attack state).

Privacy & Terms