GetKeyDown doesn't work in if statement, but GetKey does

Hello, I have been trying to create a combat system and I ran into a problem with input. If I use GetKey it works,but if I use GetKeyDown it stops working. I checked if my if statements were working and the one with input stops working the moment I change GetKey to GetKeyDown. Any idea why this might be happening? Code: (It is my first time asking a question here and it kept marking my code red and saying I need to correct the form but idk what’s wrons so the code is just in text sorry)

void Update()
{   
     if(timeBtwAttack <= 0)
    {   
        if(Input.GetKey(KeyCode.Mouse0))
        {       
                Debug.Log("Mouse0Down") ;
                playerAnim.SetTrigger("Attack");
                Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(attackPos.position,attackRange,whatIsEnemy);
                for (int i = 0; i< enemiesToDamage.Length; i++){
                enemiesToDamage*.GetComponent<Enemy>().TakeDamage(damage);*

}
Collider2D[] enemyProgectiles = Physics2D.OverlapCircleAll(attackPos.position,attackRange,whatIsProjectile);
for (int i = 0; i< enemyProgectiles.Length; i++){
enemyProgectiles*.GetComponent().DestroyThis();}*
}
timeBtwAttack = startTimeBtwAttack;
}
else
{ // Debug.Log(“Mouse0Up”) ;
timeBtwAttack-=Time.deltaTime;

playerAnim.SetBool(“AttackExit”, true);
}

}
Edit: I have tried using Get(Mouse)ButtonDown and Get(Mouse)Button and it is exactly the same as GetKey stuff

I think the problem is that you are setting timeBtwAttack back to startTimeBtwAttack when it reaches 0 or negative. Using GetMouseButtonDown or GetKeyDown would work only if you pressed the button in that particular frame - which is very unlikely.

Try this:

void Update()
{
    if (timeBtwAttack > 0)
    {
        timeBtwAttack -= Time.deltaTime;
    }

    if (Input.GetMouseButtonDown(0))
    {
        if (timeBtwAttack <= 0)
        {
            Debug.Log("Mouse0Down");
            playerAnim.SetTrigger("Attack");
            Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(attackPos.position, attackRange, whatIsEnemy);
            for (int i = 0; i < enemiesToDamage.Length; i++)
            {
                enemiesToDamage*.GetComponent<Enemy>().TakeDamage(damage);*

}
Collider2D[] enemyProgectiles = Physics2D.OverlapCircleAll(attackPos.position, attackRange, whatIsProjectile);
for (int i = 0; i < enemyProgectiles.Length; i++)
{
enemyProgectiles*.GetComponent().DestroyThis();*
}

timeBtwAttack = startTimeBtwAttack;
}
}
else if (Input.GetMouseButtonUp(0))
{
playerAnim.SetBool(“AttackExit”, true);
}
}
Note that i’m checking timeBtwAttack twice, but it shouldn’t be a problem.