CoolDown system don't work properly

helo, i try to make a 2 cube fighting with an attack and i think it will be no fun
if i can spam the attack, less startegy.
then i try to make a cooldown in my attack which it look like this:

if (attackTimer > 0)
			attackTimer -= Time.deltaTime;
		

		if (attackTimer < 0)
			attackTimer = 0;
		//pencet spasi
		if (Input.GetKeyUp (KeyCode.Space)) {
			//when attack timer reach 0
			if(attackTimer == 0)
			//call attack
			Attack();
			//attack timer back to cooldown
			attackTimer = coolDown;

now the problem is, if i try to spam the spacebar the attacktimer will be reset to cooldown time.
so if the player spam a space, he will never get a chance to attack cause the
attacktimer reset each time he press space button.
anyone can gimme a suggestion what i should do to make
the attacktimer run till the time up even we spamming the space bar?

any answer will help! thanks!

Considering the rest of your code is fine - this should work:

    if (attackTimer > 0) attackTimer -= Time.deltaTime;
    //pencet spasi
    if (Input.GetKeyUp(KeyCode.Space))
    {
        //when attack timer reach 0
        if (attackTimer <= 0)
        {
            //call attack
            Attack();
            //attack timer back to cooldown
            attackTimer = coolDown;
        }
    }

P.S. Just to clarify it a bit for you - you forgot to include your “attack timer back to cooldown” inside your if statement. I’ve also removed useless line of reseting timer to zero and corrected your “when attack timer reach” to use “equal or less” because considering that you subtract deltaTime - you most likely use float variable for your timer, not to mention that it is deltaTime in the end.