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 Adam 10 · Feb 23, 2011 at 04:23 PM · collidersoncollisionenterchildren

Child Collider Question Cant seem to get it right

So, I have read many things on using colliders on Children Objects and yet I can't seem to wrap my head around it. My last attempt was with a gameObject which was a Circular/Sphere model and on the outside it has cubes for lights. I want the player's bullets to collide with the cubes and decrement their health so that when they are all destroyed the parent object is destroyed. One attempt was on the Parent GameObject:

var light1 : Collider; var light2 : Collider;

function OnCollisionEnter(info : Collision){ Debug.Log(info.gameObject.tag); }

This returns my Bullet tag and switch the information is all the Bullet information not the Lights. So, my thought was ok I'll just check in the Bullets script:

   function OnCollisionEnter(info : Collision){
    Debug.Log(info.collider.name);
    }

Now at first this appeared to work, however only on the last Collider. So with two it was saying the Collider Light2 was hit when I am shooting Collider Light1. If I remove the second collider it says Light1 and if I have 3 then Light3 collider is always hit.

Eventually it will do

function OnCollisionEnter(info : Collision){ if(info.collider.name == "Light1" && info.gameObject.tag == "Bullet"){ light1health = light1health--; if(light1health == 0){ Destroy(Light1);} }

if(info.collider.name == "Light2" && info.gameObject.tag == "Bullet"){ light2health = light2health--; if(light2health == 0){ Destroy(Light2);} }

function Update(){ if(light1health == 0 && light2health == 0) { Destroy(Sphere); } } }

Of course for the Destroy I will have to specify GameOjects and the like, but I just can't seem to get the effect I need. My Bullet has a rigidbody and the sphere has a rigidbody. If the info.collider.name is incorrect forgive me, but I am going off memory cause the code isn't here, but the Debug did output the info needed. And yes I see the last code probably won't work like that, but I thought it might better show exactly what I am going for. Any ideas? May instead of the info.collider.name == "Light1" it would be getCompentinChildren() or something, but it's like I am dancing around the answer and just need pointed in the right direction.

An alternative is putting empty gameObjects with the colliders updating to the exact position/rotation of where the lights are, but that seems really more work than what needs to happen.

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

1 Reply

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

Answer by Adam 10 · Feb 24, 2011 at 04:45 PM

Ok, I had read this before and I guess I just didn't use it right the first time.

function OnCollisionEnter(collisionInfo : Collision)
{
        if(collisionInfo.gameObject.tag == "Bullet"){
              for(ContactPoints c in collisionInfo.contacts){
                      if(c.thisCollider.name == "MyColliderName"){
                         lightHealth--;
                         }
                      }
             }
}

Again I am going off memory, but I will correct this when I get home in case anyone else sees this.

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

No one has followed this question yet.

Related Questions

Transform child out of bounds. 0 Answers

Trigger in child object calls OnTriggerEnter in parent object 3 Answers

collisions not detected 1 Answer

Collision returned from OnCollisionEnter2D and OnCollisionExit2D are not the same 1 Answer

Trigger on Child making calls to OnTrigger in Parent 2 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