- Home /
How to slowly decrease health script?
I have been looking for a script to slowly decrease the health of a player. (e.g when in a fire environment)
I currently have a basic script that will display the health bar, can anyone help me create a script to gradually reduce the players health?
var health100 : Texture2D; var health95 : Texture2D; var health90 : Texture2D; var health85 : Texture2D; var health80 : Texture2D; var health75 : Texture2D; var health70 : Texture2D; var health65 : Texture2D; var health60 : Texture2D; var health55 : Texture2D; var health50 : Texture2D; var health45 : Texture2D; var health40 : Texture2D; var health35 : Texture2D; var health30 : Texture2D; var health25 : Texture2D; var health20 : Texture2D; var health15 : Texture2D; var health10 : Texture2D; var health5 : Texture2D; var health0 : Texture2D;
var LIVES = 21;
function Update () { switch(LIVES) { case 21: guiTexture.texture = health100; break;
case 20:
guiTexture.texture = health95;
break;
case 19:
guiTexture.texture = health90;
break;
case 18:
guiTexture.texture = health85;
break;
case 17:
guiTexture.texture = health80;
break;
case 16:
guiTexture.texture = health75;
break;
case 15:
guiTexture.texture = health70;
break;
case 14:
guiTexture.texture = health65;
break;
case 13:
guiTexture.texture = health60;
break;
case 12:
guiTexture.texture = health55;
break;
case 11:
guiTexture.texture = health50;
break;
case 10:
guiTexture.texture = health45;
break;
case 9:
guiTexture.texture = health40;
break;
case 8:
guiTexture.texture = health35;
break;
case 7:
guiTexture.texture = health30;
break;
case 6:
guiTexture.texture = health25;
break;
case 5:
guiTexture.texture = health20;
break;
case 4:
guiTexture.texture = health15;
break;
case 3:
guiTexture.texture = health10;
break;
case 2:
guiTexture.texture = health5;
break;
case 1:
//gameover script here
break;
}
}
EDIT***
After looking around some more I have come across a thread that seems relevant to what I want. But the problem Im having is combining the first script with the new one?
Answer by Justin Warner · May 18, 2011 at 01:15 AM
Just subtract a life when player is in the fire... Check again in 3 seconds, and keep subtracting... Pretty easy.
Save the time, compare it with the refreshed time, but add 5 to the saved time, then that'll make it every 5 seconds...
Look around, easy.
Answer by Dreamer · May 18, 2011 at 01:39 AM
I think what Ben wants is a health bar system replace of changing 21 pictures manually to represent current health.
Refer to below example of how to make a health bar:
Answer by Ben 39 · May 20, 2011 at 12:15 AM
How would I use this code with the code above. Ive tried simply attaching the script to the player and tagging a sphere collider "Fire", but the code still does not work...any suggestions?
thanks for your help
function OnTriggerStay(collisionInfo : Collider){
if(collisionInfo.gameObject.tag == "Fire"){
Health-=FireDamage*Time.deltaTime *1;
enable = false;
yield WaitForSeconds(1);
enabled = true;
}
}
}
Your answer
Follow this Question
Related Questions
Decrease Health every 5 mins or Time script? 2 Answers
How To Make Health Decrease 4 Answers
progress bar 1 Answer
How do I set a max limit for my health value? 4 Answers
Empty Health Bar, remove one life 2 Answers