hey, i have a problem getting this script to work right!

static var health : int = 340;
private var hitPoints: int;
private var backup = [health];
static var Hit : boolean;

function OnGUI () {
    GUI.Box(Rect(8,9,350,40), "Life");
    GUI.Box(Rect(13,25,health,20),"");
}

function Update () {
    hitPoints = Hunt.killPoints;
    if(Player_Simply.dead == false && Hit == true) {
        health -= hitPoints * Time.deltaTime;
    }
    if(health <=1){
        Player_Simply.dead = true;
        health = backup[0];
    }
}   

my basic problem is, that when ever the static var dead is true, my player gets respawn. normally this script should then set the health var back to its maxHealth, but the player is still losing health! can u guys help me?

There are two things to consider:

Health regeneration

You set health to backup[0] .... why are you storing an array for one int?...If backup[0] is not a valid number, your health will not be reset to a value you expect.

What it takes to get damaged

Assuming your health is getting reset, the next thing to consider is the condition under which you take damage:

Player_Simply.dead == false && Hit == true

  • (Ignoring the terrible name) Player_Simply, assuming this.dead actually indicates that your player is alive then this will be true every frame that your player is alive, meaning that they can take damage as long as they are alive.
  • The only thing needed to take damage when you are alive (assuming the above variable is set properly) is for the boolean Hit to be true.

If you keep taking damage when you don't intend to, it must be that at some point you should probably set Hit to false but haven't.