Delay after Attack Button and Decreasing Mana Bar

Good Afternoon! My name is Abel and I’m a beginer in this world, so I need some help…

I have made a GUI with some buttons, and one of that have the function to decrease the health of a monster, but if you press the button fast, you can kill the monster in less that 1 second, so I want to ask how I can do a delay mecanism that activate itself after pressing the attack button and doesn’t allow you to press the button again before the delay finish. I tried to do it with a for that contains a waitForSeconds, inside the button code (if()), but it doesn’t work.

And also I have another little question. I have a mana bar that decrease when pressing a button in my game and i want to create a progressive decreasing bar, I mean, I want it to decrease slowly, and not to make the bar smaller instantaneously after pressing the button. Is it clear?

The button is only a if(GUI.Button(Rect(x, y, x, y), “”)) States.mana-10;, and there is a mana bar which width is given by this State.mana var.

Thank you a lot!
Abel!

Here, try something like this.

using System.Collections;
using UnityEngine;
using System;

public class FightEnemy : MonoBehavior
{
	public float attackTime, waitTime = 1.0f;
	protected bool canAttack = true;
	
	public void OnMouseDown()
	{
		attackTime = Time.time;
		if(canAttack)
		{
			Enemy.TakeDamage(1); // This is pseudo code, obviously just an example.
			canAttack = false;
		}
	}
	
	public void Update()
	{
		if(!canAttack)
		{
			if(Time.time > attackTime + waitTime)
				canAttack = true;
		}
	}
}