Hello everybody, got a problem with this script. When I click too fast the button it skips straight to the 3rd animation and afterwards returns to the 2nd to finish the cycle shouldn’t the line
if (current_Combo_State == ComboState.Step3)
return;
prevent any issue like this one?
I tried everything: adding && current_Combo_State == ComboState.Step2; make the animation almost the same time of the private float default_Combo_Timer = 0.3f; inverting step 3 and step 2 (but if I do that, i end up playing step 1, step 3, step 2 if I press the button slower).
public enum ComboState
{
NONE,
Step1,
Step2,
Step3
}
public class AttackCombo : MonoBehaviour
{
private Animator anim;
private bool activateTimerToReset;
private float default_Combo_Timer = 0.3f;
private float current_Combo_Timer;
private ComboState current_Combo_State;
void Awake()
{
anim = GetComponent<Animator>();
}
// Start is called before the first frame update
void Start()
{
current_Combo_Timer = default_Combo_Timer;
current_Combo_State = ComboState.NONE;
}
// Update is called once per frame
void Update()
{
ComboAttacks();
ResetComboState();
}
void ComboAttacks()
{
if (Input.GetKeyDown(KeyCode.I))
{
if (current_Combo_State == ComboState.Step3)
return;
current_Combo_State++;
activateTimerToReset = true;
current_Combo_Timer = default_Combo_Timer;
if(current_Combo_State == ComboState.Step1)
{
anim.SetTrigger("Slash1");
}
if (current_Combo_State == ComboState.Step2)
{
anim.SetTrigger("360");
}
if (current_Combo_State == ComboState.Step3)
{
anim.SetTrigger("GSS3");
}
}
}
void ResetComboState()
{
if (activateTimerToReset)
{
current_Combo_Timer -= Time.deltaTime;
if(current_Combo_Timer <= 0f)
{
current_Combo_State = ComboState.NONE;
activateTimerToReset = false;
current_Combo_Timer = default_Combo_Timer;
}
}
}