Issue with timer in combo attack

Hello,

I am trying to create a simple combo system for my game. I have a script that almost works but I have an issue with combo attack timer. So the problem is that inside my AttackAnimation() function I start the timer by setting activateTimerToReset to true and then I increment currentComboState to perform next combo attack. However inside the ResetComboState () my currentComboState is also incremented so instead of easyCombo [0] I have easyCombo [1] and so on, which means that function starts the timer of the wrong combo hit and also it doesn’t reset the timer. Is there any way to solve this issue?

Here’s my script so far:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class AttackSystem : MonoBehaviour {

public AttackCharacteristics[] easyCombo = new AttackCharacteristics[3];

private float originalTimer;
private int currentComboState = 0;
bool activateTimerToReset = false;
Animator anim;

void Start () 
{
	originalTimer = easyCombo [currentComboState].comboMaxTime;
	anim = GetComponentInChildren <Animator> ();
}

void Update ()
{
	if (Input.GetKeyDown (KeyCode.A))
		AttackAnimation();
	
	ResetComboState (activateTimerToReset);
}
	
void AttackAnimation()
{
	switch (currentComboState)
	{
	case 0:
		activateTimerToReset = true;
		anim.SetTrigger(easyCombo[currentComboState].animTriger);
		currentComboState++;
		Debug.Log ("1 hit.");
		break;
	case 1:
		anim.SetTrigger(easyCombo[currentComboState].animTriger);
		currentComboState++;
		Debug.Log ("2 hit");
		break;
	case 2:
		anim.SetTrigger(easyCombo[currentComboState].animTriger);
		Debug.Log ("3 hit!");
		currentComboState = 0;
		break;
	}
}

void ResetComboState (bool _timerToReset)
{
	if (_timerToReset) 
	{
		easyCombo [currentComboState].comboMaxTime -= Time.deltaTime;

		if(easyCombo [currentComboState].comboMaxTime <=0)
		{
			currentComboState = 0;
			activateTimerToReset = false;
			easyCombo [currentComboState].comboMaxTime = originalTimer;
			anim.SetTrigger("BreakCombo");
		}
	}
}

}

[System.Serializable]

public class AttackCharacteristics

{

public string animTriger;
public float comboMaxTime;

}

Sorry, i fail to see where your currentComboState is incremented a second time. You set it to 0 in 2 places, but only 1 place (the switch) increments it.

Edit : below an exemple on autocycling :

    public class AttackSystem : MonoBehaviour
    {
        public AttackCharacteristics[] easyCombo = new AttackCharacteristics[3];
        public AttackCharacteristics currentCombo;

        private float timer;
        private int currentComboState;
        private bool activateTimerToReset = false;
        private Animator anim;

        void Start()
        {
            ChangeCombo(0);
            anim = GetComponentInChildren<Animator>();
        }

        void Update()
        {
            if (Input.GetKeyDown(KeyCode.A))
                AttackAnimation();

            ResetComboState(activateTimerToReset);
        }

        void AttackAnimation()
        {
            if (currentComboState == 0)
            {
                activateTimerToReset = true;
            }
            anim.SetTrigger(currentCombo.animTriger);
            Debug.Log((currentComboState + 1) + "hit.");                
            //Cycle trough elements of easyCombo
            ChangeCombo((currentComboState + 1) % easyCombo.Length);
        }

        void ResetComboState(bool _timerToReset)
        {
            if (_timerToReset)
            {
                timer -= Time.deltaTime;
                if (timer <= 0)
                {
                    ChangeCombo(0);
                    activateTimerToReset = false;
                    anim.SetTrigger("BreakCombo");
                }
            }
        }

        void ChangeCombo(int index)
        {
            currentComboState = index;
            currentCombo = easyCombo[index];
            timer = currentCombo.comboMaxTime;
        }

    }