In this script I am trying to make it so that the players health degenerates at a constant rate of 1 health every 1 second but it is zipping from 100 health to 0 health in about 3 seconds. Any thoughts on what I need to change to make it work properly?
static var health = 100;
var maxHealth = 100;
var dieDuration =3;
var degen = 1;
//Degenerate health and display health on the guitext
function Update(){
health -= degen * Time.deltaTime;
HealthManager.hitPoints = CharacterDamage.health;
}
//Take damage and die if health reaches 0
function ApplyDamage (amount : float){
health -= amount;
if(health < 1);
Die();
}
function Die(){
yield WaitForSeconds( dieDuration );
Destroy(gameObject);
}
//If you get destroyed restart the level
function onDestroy(){
Application.LoadLevel(0);
}
UPDATED SCRIPT
static var health : float = 100;
var maxHealth = 100;
var degen : float = 1;
function Update(){
ApplyDamage(degen*Time.deltaTime);
HealthManager.hitPoints = CharacterDamage.health;
}
function ApplyDamage (amount : float){
health -= amount;
if(health < 1)
Die();
}
function Die(){
Application.LoadLevel (0);
}