So in my script, it seems as if the health value doesn’t get changed at all. On line 8 it prints the health value (which I set to be 100) and on line 26 it correctly prints the health with damage subtracted. The issue is that the actual health value (the one in another game object) doesn’t get changed at all. I can manually change it and it’s all good, but the script below wont actually change it. It just prints on line 26 the value as if it were changed.
function OnCollisionEnter(other : Collision) {
if(other.collider.GetComponent(HealthSystem)) {
Debug.Log("This1");
HealthS = other.collider.GetComponent(HealthSystem);
Debug.Log("This2");
Health = HealthS.Central.GetComponent(CentralHealth).Health;
Debug.Log("This3");
Debug.Log(Health);
if(HealthS.IsHead == true) {
Debug.Log("Hit something!");
Health -= Damage;
}
else if(HealthS.IsTorso == true) {
Debug.Log("Hit something!");
Health -= Damage / 2;
}
if(HealthS.IsArm == true) {
Health -= Damage / 3;
}
if(HealthS.IsLeg == true) {
Health -= Damage / 2.5;
}
if(HealthS.IsOther == true) {
Health -= Damage / 2;
}
Debug.Log(Health);
}
else {
Debug.Log(other.collider.name + " Does not have HealthSystem script attached! ");
}
//if(hit.gameObject.tag != "Metal" && hit.gameObject.tag != "Wood" && hit.gameObject.tag != "Stone" && hit.gameObject.tag != "Dirt") {
//}
Destroy (gameObject);
}