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