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 TimeBlink · Apr 15, 2013 at 07:58 PM · prefabparentchildrenunity 4

Trigger in children object activates function in parent

My prefab is a sphere with an empty game object (that has a trigger) attached to it. It is supposed to represent a bomb.

The way it is supposed to work: The prefab is thrown at an enemy. When the "bomb" makes contact with another gameObject that has the tag enemy it sends a message to the empty game object. Then, the empty object destroys all the gameObjects with the "enemy" tag within its trigger.

The way it works: The prefab is thrown at an enemy. When an enemy touches the trigger of the empty object the message that destroys the gameObjects is sent.

I recently updated my project from unity 3 to 4. Everything was working correctly before the update. I haven't changed anything in the code but my object behaves differently, now.

The script from the sphere:

 public class BombCollision : MonoBehaviour {
     
     // When an enemy hits the bomb, a message is sent to the child object that has the tigger attached
     void OnTriggerEnter (Collider collider) {
         // Debug.Log ("Hit something that is not an enemy");
         if (collider.gameObject.tag == "Enemy") {
             // Debug.Log ("Hit the bomb");
             BroadcastMessage("EngageTargets");
             StartCoroutine("timeForExplision");
         }
     }
     
     // gives time for BombKiller to destroy the objects are within the collider before destroying the bomb
     IEnumerator timeForExplision () {
         yield return new WaitForSeconds(0.05f);    
         Destroy(gameObject);
     }

The script from the empty game object attached to the sphere:

 public class BombKiller : MonoBehaviour {
     
     bool contact = false;
     
     void OnTriggerStay (Collider collision) {
         if (collision.gameObject.tag == "Enemy" && contact == true) {
             collision.SendMessage("WasHit");
         }
     }
          
     void EngageTargets () {
         Debug.Log ("got engageTargets");
         contact = true;    
     }
 }

I've tried to solve this for a whole day now, I hope someone can help me out, thanks for reading.

Comment
Add comment · Show 3
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 nah0y · May 17, 2013 at 03:16 PM 0
Share

Hi !

Check this thread : http://forum.unity3d.com/threads/26194-Compound-Colliders-and-Trigger-Scripts

If your parent have a rigidbody, and the children gets collided, the parent trigger is called.

I also did not had this issue before upgrading to Unity 4... looking into it.

avatar image TimeBlink · Jun 09, 2013 at 04:30 PM 0
Share

Thanks for your reply! I was able to work around this issue by setting the child collider to inactive and then setting it to active when an enemy collided with the parent. I hope you were able to solve the issues upgrading to Unity 4 caused. Sorry it took so long to reply I moved and did not have internet for almost a month!

avatar image nah0y · Jun 10, 2013 at 11:00 AM 0
Share

No problem! Glad I could help :) Also yes I resolved it, but by using 2 rigidbodies !

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

12 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

Related Questions

Problem with prefab parent and children objects that need to be instantiated multiple times. 1 Answer

Accessing children of instances vs children of original prefab 1 Answer

Make a simple tree 1 Answer

Photon Instantiate Prefab Script Problems 0 Answers

Child and Parent, both at 0,0,0, but not on screen 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