Looking for skilled individual to assist with problem

Well let me start out by saying that i've been for 4 days, two hours each day, attempting to get this code to function properly. It's a simple health script. I've been able to get the code to successfully receive the damage given to it by a cube and update its own current health. Sadly the cube receiving the damage is not destroying itself when its health reaches zero. So i was wondering if anyone had a possible suggestion to fix this problem. heres the code for health script.

var healthMax = 100;
var curHealth = 100;
var dieHealth = 0.0;

function Awake () {

if (curHealth <  healthMax) {
}

if(curHealth <= dieHealth) {

    die();

}

}

function die () {

Destroy(gameObject);

}

function ApplyDamage (damage : float) {

    curHealth -= damage;
    print (curHealth);
}

also here's the code for the damage script.

var damage = 10;

function OnCollisionEnter (col : Collision) {

col.gameObject.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
print (damage);

}

1 Answer

1

Awake is called just one time when the instance is created. You have to do your check everytime when you change the health.

function ApplyDamage (damage : float) {

    curHealth -= damage;
    print (curHealth);
    if(curHealth <= dieHealth) {
        die();
    }
}