Hello, I need some help with this melee/combat script of mine. I want to make a 3 hit combo attack, but at the moment the two attack animations I have in the code are playing at the same time when you press the listed button. I don’t know whether I’ve made a mistake with the timer or done something wrong in the animator.
private float attackTimer = 0f;
private float cooldown = 1.3f;
private int combo = 0;
private bool attack1;
private bool attack2;
private void MeleeAttack()
{
if (Input.GetButtonDown("Attack1") && !attack1 && attackTimer <= 0 && combo == 0)
{
attack1 = true;
attackTimer = cooldown;
playerAttackAnim.SetBool("isAttacking", attack1);
combo++;
}
if (attack1)
{
if (attackTimer > 0)
{
attackTimer -= Time.deltaTime;
if (Input.GetButtonDown("Attack1") && !attack2 && attackTimer > 0 && combo == 1)
{
TransitionToAttack2();
}
}
else
{
if (attackTimer < 0)
{
attackTimer = 0;
combo = 0;
attack1 = false;
attack2 = false;
playerAttackAnim.SetBool("isAttacking", false);
playerAttackAnim.SetBool("isAttacking2", false);
}
}
}
}
private void TransitionToAttack2()
{
attack2 = true;
attackTimer = cooldown;
playerAttackAnim.SetBool("isAttacking2", attack2);
combo++;
}