Update going multiple times even though condition is false

I’m trying to make a life system in my game. So you die and lose a life. For some reason though, the die script im using keeps going even though the condition isn’t true.

 function Update () {
if(playerHealth <= 0 && !isDead) {
   playerHealth = 0;
    levelManager.RespawnPlayer();
    lifeSystem.TakeLife();
isDead = true;
  // player.GetComponent(PlayerMove).doDeathAnimation = true;
  //player.GetComponent(Rigidbody2D).isKinematic = true;
}
//other code here
}

The take life function :

 function TakeLife() {
lifeCounter --;
print(lifeCounter);
}

You probably do not reset your playerHealth, once died, it appears to stay 0 and the condition is true (<= 0).
A computer only does what he’s told to do and if it runs the code, it’s the programmers fault :stuck_out_tongue:

1 Like

Not enough information, tbh. You should post what your RespawnPlayer functions and such do. Only current suggestion I can give is to maybe move your “isDead = true;” statement above your function calls to be just under your “playerHealth = 0;” because maybe your function calls are doing something and that flag coming after them is doing something wonky?

Thanks so much! That is exactly what was wrong. Can’t believe I missed that!