- Home /
health regeneration after death
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?
This looks substantially similar to http://answers.unity3d.com/questions/24184/health-system-problems but with code this time. Perhaps you should consider closing the older question.
Answer by skovacs1 · Oct 21, 2010 at 07:22 PM
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.
thanks u were right, i just needed to set it to false! and the name is terrible, but this is just a test game. I need to make a video about this game, how i made it and everything, so i have more then one player scripts, and this one is the simple one (with out any animations)
Your answer
Follow this Question
Related Questions
How Do I Make A Health Bar 6 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Health subtracts when hit by bullit 2 Answers
Regain health on GUI 2 Answers
Help w/variables 0 Answers