void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.name == “KP”) {
StartCoroutine(DamagePlayer());
DamagePlayer();
StartCoroutine(DamagePlayer());
}
}
public IEnumerator DamagePlayer() { //waits but doesnt force code to stop, make it do that
yield return new WaitForSeconds(1);
GameObject.Find(“KP”).GetComponent().DamagePlayer(damage);
print(“Waited”);
}
My wait function does work in that it halts any damage being done to after one second, but all of the damage floods in after that one second. What I need is for the enemy to only deal damage once per every second and time the player hits the enemy, not constant damage while the player is touching the enemy.