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 Turkeybag · Oct 16, 2013 at 04:27 AM · collisioncollidertransformgetcomponentparent

Having trouble understanding parenting with componants

Alright so I'm having a hard time getting things to work with parenting due to one reason, I can't wrap my head around the way it works. It's just so seemingly inconsistent that I can't figure it out. The way it changes the way get component works seems to be different every time. Alright so I have two objects with the "MobStats" script on them. The MobStats script handles mob health.

One of these objects is the child of another object (you have to shoot a specific part of him to damage him), the other is the parent of 2 other objects. I also have 2 ways of calling the damage function on the MobStats script:

 void OnTriggerEnter (Collider Hit){
     HitTransform = Hit.transform;
     Debug.Log(HitTransform.gameObject);
     if (HitTransform.GetComponent<MobStats>())
     {
         DamageMob = HitTransform.GetComponent<MobStats>();
         DamageMob.DamageMob(Damage);
     }
 }

and

 void OnCollisionEnter (Collision WasHit){
     HitByCannon = WasHit.transform;
         Debug.Log(HitByCannon.gameObject);
     if (HitByCannon.tag == "Enemy")
     {
         DamageMob = HitByCannon.GetComponent<MobStats>();
         DamageMob.DamageMob(Damage);
     }
     Destroy(gameObject);
 }

They both use the transform of whats it. This is where I start to get confused, the OnTriggerEnter script (ball that expands until it takes up the whole level and should hit everything) just flat out wont hit either of the two objects although 1/10 times it seems to hit every part of the object instead. Debug comes up with no object, or every object in the hierarchy. When I put the part with the MobStats script on it's own, it hits it every time. The only thing more confusing than this is how my OnCollisionEnter works.

My gun fires a small projectile with the OnCollisionEnter script on it and if it hits the object where MobStats is on the parent, then it will debug the parent object every time no matter what it hits in the hierarchy. However if it hits the object where MobStats is in the child object, it will debug the child object every time meaning I get an error if it hits any part of the object without the script as it still tries to access it. I could check if the object has the script but that's besides the point.

Is anyone able to explain why it seems to act in a different way everytime? Is there a way to do something similar to parenting that doesn't change the way get component and collisions works?

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

14 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

Related Questions

Stop moving when colliding. 2D 1 Answer

Multiple Colliders With Mechanim 1 Answer

How can I get Compound Colliders to work properly? 2 Answers

How to detect child object collisions on parent 3 Answers

How to activate parent camera of gameobject -1 Answers


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