Player Health Not Working?

Hi, I have a player with three lives (The lives are represented by gameobjects). My script is meant to make the player lose a life when they collide with a hazard (Trigger), they can hit only three hazards before being destroyed. The problem is, that when I hit a hazard; my player loses one life, and on the second hit, they lose both leftover lives and the player is destroyed instantly. Why does this happen all of a sudden? I had my script working perfectly beforehand. :confused:

Script:

#pragma strict

// Controls player health using 3 lives, 2 of which are visable

var fullHealth : int = 3;
var curHealth : int = 3;
var player : GameObject;
var explosion : GameObject;
var life1 : GameObject;
var life2 : GameObject;
 
function OnTriggerEnter(collider : Collider) {
    if(collider.tag == "Hazard") {
        curHealth -= 1;
    }
}
function Update () {
 	if(curHealth >= fullHealth){
    curHealth = fullHealth;
}
	if(curHealth == 2){
    	curHealth = 2;
    	Destroy(life2);
    	}
	if(curHealth == 1){
    	curHealth = 1;
    	Destroy(life1);
    	}
 	if(curHealth <= 0){
    	curHealth = 0;
    	Destroy(player);
    		Instantiate(explosion,transform.position, transform.rotation);
    	}
}

I find a short period of invincibility immediately after hitting the trigger works well. You can do this by setting a bool on either the trigger or the player.

Perhaps you have an animation causing the trigger to trigger multiple times?
Like a stumble or a knockback animation that makes the trigger move out and then back in.

Maybe you dublicated “Hazard” object and forgot to move so there may be 2 Hazard object inside each other.

Alrighty! I’ve just come across something very strange, my player was dying on the second hit with the “average sized” trigger. When I shrank it down or made it bigger, things began to work again. Strangely though, any other trigger of the same size didn’t effect the player like the “buggy” one did. I guess it was all just a collision problem. Thank you to everyone that put in and helped! It was very appreciated! :stuck_out_tongue: