- Home /
Debug log doesn't always activate?
In this part of my script, should the debug log not print this1, 2, and 3 each time it hits the requirement? I think this is the reason my script isn't working properly. It does debug log the health near the bottom of the script every time it hits the requirement though. Sorry if the coding is extremely dirty.
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;
}
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);
}
Be sure you don't have (Collapse) checked on the log pane, it won't repeat messages if you do
Yep, completely right. Still gotta figure out the issue though...
So it's hitting line 26 above but not the other debug lines?
No it is, but my system is screwed up. The damage is given to the health value, but nothing actually happens.
Every time line 8 prints 100 (healths value I manually set) and line 26 prints Health with the damage added on. It does that every time I shoot.
Shouldn't line 8 adjust to the newly assigned value?? Why does it just reset?
ok, so the debug.log statements are printing out, they're just not showing you what you expect?
Answer by Will Davis · Sep 06, 2013 at 10:14 AM
Looks like a scope issue of Health verses the HealthS.Central.GetComponent(CentralHealth).Health..
what about HealthS.Central.GetComponent(CentralHealth).Health = Health;
before destroying the gameobject? does that give better results.
Your answer
Follow this Question
Related Questions
Health value isn't subtracting correctly 1 Answer
A node in a childnode? 1 Answer
Can I see debug log(ex:printf) from C++ dll in Unity? 0 Answers
Stack Trace returns null ?? wtf with my unity today? 3 Answers
Death upon health = 0 2 Answers