- Home /
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);
}
Answer by Bunny83 · Apr 07, 2011 at 12:52 PM
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();
}
}
Your answer
Follow this Question
Related Questions
Character controller mess up damage 3 Answers
Health and damage reciever 1 Answer
Player health system won't subtract health 1 Answer
damage system 0 Answers
Health Script 1 Answer