How do I make a prefab ignore collisions with another prefab temporarily.

I am currently working on a platformer game that involves a death animation once the player has run out of health. I am wanting the player to be able to ignore 2d collisions with an enemy, as it is going through the animation. I have already tried using the code: Physics2D.IgnoreCollision(Player.GetComponent(), Enemy.GetComponent());

But this only works for a single enemy not all of them. I have attached the enemy prefab to the player under a game object, but still no luck.

Appreciate the Help

Set different layers for enemy and player,

when animations starts:

Physics2D.IgnoreLayerCollision (playerLayer, enemyLayer, true) 

when the animation ends:

Physics2D.IgnoreLayerCollision (playerLayer, enemyLayer, false) 

Physics2D.IgnoreLayerCollision

In your animation, you can simply disable the player collider, and then re-enable it after your animation is finished.

185273-animationcollider-example.png