- Home /
Weird problems with exectution orders and just simple bools????
I'm using C#, and I have 3 scripts. 1 is a bullet script to shoot with raycast, another goes on my enemy, and another on each limb of my enemy (for "blowback purposes :D)
The problem is, on my bullet script, I'm trying to detect if the enemy is dead inside of the enemy script (the bullet script is 'GunShootMagazine', the enemy is 'KillZombie', and the limbs scripts are called 'ZombieLimb'). Here's the codes:
KillZombie
if (enemyHealth <= 0) {
Debug.Log ("Enemy Dead!!");
//Make the bones flap around
foreach (Rigidbody rigidbodyFore in rigidbodies) {
rigidbodyFore.isKinematic = false;
}
animer.enabled = false;
GetComponent<PlayAnimations> ().enabled = false;
iAmAlive = false;
enabled = false;
}
Bullet Script
if (hitObject.transform.root.GetComponentInChildren<KillZombie>().iAmAlive == false) {
Debug.Log ("AddForceToMe should now be true(it should be 'true false' under this)");
hitObject.transform.GetComponent<ZombieLimb>().addForceToMe = true;
}
if (hitObject.transform.root.GetComponentInChildren<KillZombie>().iAmAlive == true) {
hitObject.transform.root.GetComponentInChildren<KillZombie>().enemyHealth -=damage;
Debug.Log ("Enemy Lost Health! " + hitObject.transform.root.GetComponentInChildren<KillZombie>().enemyHealth);
}
And my Limb Script
if (addForceToMe) {
rigidbody.AddForce (Vector3.forward * 1000);
Debug.Log ("Added force to " + this.transform.name);
enabled = false;
}
Ok, so my problem is I'm trying to set the limbs' "addForceToMe" to true when the zombie is dead. I HAVE to have it be detected from my bullet script so it knows which limb part to apply it to. When it tries to see if the zombie is dead in the bullet script, it keeps skipping over that as if it's not dead. I don't know why I'm a little brain dead right now from thinking about this so much. If anyone knows the reason, help would be appreciated! Thanks for reading (any more details can be provided) Thanks!
Wait, I'm confused. I mean it is a zombie game, so maybe you're code is written as such, but why would you add force to a limb if the zombie is dead (I mean you're checking iAmAlive == false before you set the addForceTo$$anonymous$$e value to true). Unless by iAmAlive == false means he is dead which means he is attacking you, but that would get confusing, and it appears in the first script you don't set the iAmAlive to false until health is gone, so the iAmAlive flag really means he is dead, but like a zombie dead (alive), lol. Sorry I couldn't resist! Oh, you should add a flag called unDead. :)
So, seriously, did you mean to check iAmAlive == false in the bullet script? I think you would want to check true, then blow off each limb, but maybe that's not your mechanic.
Also, you do realize the irony that you are brain dead (your words not $$anonymous$$e!) while working on a zombie game. That's cool, you can just tell people you're getting into the role. :)
EDIT: Do you get any of these prints??
Just a note, it's much nicer to use if (!bool) and if (bool) ins$$anonymous$$d of if (bool == false) and if (bool == true).
The reason for this comes from spoken language. Which sounds better?
"If the zombie isAlive, do"
or
"If the statement: 'The zombie isAlive' is true, do"
Answer by Firedan1176 · Mar 22, 2014 at 12:34 PM
Oh, DUHH Nevermind, I figured it out. I had the bullet script checking if the health was less than 0. I need to check if it's less than or equal to damage (so if this next bullet is the killing shot). Thanks for your responses!
Your answer
Follow this Question
Related Questions
An OS design issue: File types associated with their appropriate programs 1 Answer
C# Inheritance - Reference the INSTANCE of a variable, is it possible? 1 Answer
Accessing Variables from Another Script 1 Answer
inheritance - instance variable problem? 4 Answers
Why do I get variable not assigned? 1 Answer