# How can I handle two collisions in the same frame?

My problem is that I have a player with collisions, and enemy can collide with players collision and execute Hurt function in players script. But the problem is enemies can overlap and can hit the player in the literally same frame. So they both execute Hurt function.

In my Hurt function I change players collision layer for a 2 seconds, and he is no longer be able to seen by enemies. But it doesnt matter because of the same hit by two or more enemies in the same frame.

How can I solve this? I tried bool to check if Hurt function is executed but it doesnt work too...

Here is :

Code on Enemy:

 IEnumerator OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
//burası kediler üst üste bindiginde birden fazla kez calisabiliyor
charMovementRef.StartCoroutine(charMovementRef.Hurt());

Debug.Log("hasar yedi");
}
}


Code on Player:

//Hurt should only works one at the same time
public IEnumerator Hurt()
{
//layer değiştirerek düşman collisionlarından kaç
gameObject.layer = 9;
//canı azalt
health--;
HeartUI(); //show the new health on UI
//karakter görüntüsü yanıp sönsün
gameObject.GetComponent<SpriteRenderer>().color = new Color(1f, 1f, 1f, 0.5f);
//playerı zıplat
rb2D.velocity = new Vector2(rb2D.velocity.x, 0);