hi,
i think that you forgot to remove the dealdamge.hit(); method from the “ontrigerenter2d” method because it is actually destroying the game object at once. when I removed it from the code it worked properly.
Yeah I had the exact same problem.
Same issue happened to me
Check to see if you only have the DamageDealer component on the enemy, not the player.
Also, if you still have issues, such as you try the above and your player becomes immortal, look to see if your DamageDealer script is wrote correctly. It could be you’re missing the “other.” to your DamageDealer.
damageDealer = other.GetComponent<DamageDealer>();
This is what happened to me.
The issue with damgeDealer.Hit() was it is triggered when the player and enemy colliders collide.
We check to see if the damage dealer script is attached to the objects with damageDealer != null. (Both the player, and Enemies do indeed have the script.)
The Method Hit() in our DamageDealer class just calls to Destroy the gameObject that it’s attached to.
so they only collide once, and are both destroyed, regardless of the health you have.