I’m adding a Death Counter to my game, so every time I die, it goes up by 1. For that, I created a deaths int variable, and made it so that everytime it enters a trigger tagged with “hazard” (everything that kills my character) it goes up by one
private void OnTriggerEnter2D(Collider2D col)
{
//Death
if (col.gameObject.tag == "Hazards")
{
//Code that locks my player's control, plays a dead animation, resets the position, etc.
deaths ++;
}
}
For now, I’m trying with a Debug.Log that shows my number of deaths, but the thing is that the number is not going up consistently. Sometimes when I die and check, it goes up by one death, but sometimes it goes up up to three deaths in a single one
(I only died once in intervals like 10 to 13 deaths)
I also tried changing deaths++; to deaths += 1; but the result is still the same. It’s in the Trigger Enter method, so I suppose it theoretically should only happen when firstly touching the collision, why does it repeat? Because other codes like the particles and the sound effect doesn’t play multiple times, only the variable goes up multiple times