how to do a damage cooldown just like when you have a gun and there is an interval on every shot
Just define a boolean to check if you want to recieve damage. Maybe like this example written in C#:
Inside of your monobehaviour:
public float invulTime = 1f // The time you stay invulnerable after a hit
public float health = 100; // The players health obviously
private bool invulnerable = false; // this boolean gets checked inside of the Damage function.
public void ApplyDamage(float dmg){
if(!invulnerable){
health -= dmg;
StartCoroutine(JustHurt());
}
}
IEnumerator JustHurt(){
invulnerable = true;
yield return new WaitForSeconds(invulTime);
invulnerable = false;
}