Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Firedan1176 · Mar 22, 2014 at 04:21 AM · raycastvariablesinheritance

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!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image supernat · Mar 22, 2014 at 04:42 AM 0
Share

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??

avatar image Benproductions1 · Mar 22, 2014 at 07:19 AM 0
Share

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"

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges