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 Gnemlock · Mar 15, 2014 at 03:08 PM · collisiondestroyclass objectempty game objectalign two objects

How do I go about destroying empty game objects on collision?

I am in the process of making a simply flappy bird clone, and I have the upper and lower barricade inside an empty game object. When they exit the field they trigger a collision script

public class DestroyOnContact : MonoBehaviour { void OnTriggerExit(Collider other) { Destroy (other.gameObject); } }

simple enough. Only the empty game objects I had created to store and parent the two halves continue to stack up, failing to destroy. I have tried adding a collider to the parent object. I have even tried running the collision script from the other side, having the empty game object call and destroy itself. Nothing seems to work.

Am I going about this the wrong way? Should I instead call the two halves of the boundary individually and treat them as separate objects?

thank you in advance

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 ahaykal · Mar 15, 2014 at 04:58 PM 0
Share

make sure you have a rigidbody on them.

avatar image Gnemlock · Mar 15, 2014 at 11:10 PM 0
Share

on the empty game object, or the two boundary halves?

I don't have one presently on the empty game object, but having added one does not solve my problem

edit

this is my script on the game object grouping the two boundarys (just a simple this.kill script) I can confirm the code works if it is placed on the individual objects, but this still leaves me with needlessly cloned empty game objects.

Is there any issue I could be having simply from both boundaries existing where there is no mesh render?

 void onTriggerEnter(Collider other)
 {
     if (other.tag == "Boundary") 
     {
         Destroy (this.gameObject);
     }
 }

this is what I'm looking at. collider on the left, physical obstacle on the right.

screenshot.jpg (353.0 kB)

1 Reply

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

Answer by Gnemlock · Mar 16, 2014 at 12:39 PM

Problem solved.

I called a collision detecting script and just referenced the items parent

 Void onTriggerEnter(collider other)
 {
 Destroy(other.transform.parent.gameobject);
 }

Treating collision off just the parent gameobject was not working because the rigidbody and the collision box were not moving in line with the children. The children also needed rigidbodies to behave correctly and i think this caused altered movement between the parent and its children.

Comment
Add comment · Show 1 · 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
avatar image prehisto · Apr 25, 2015 at 10:04 PM 0
Share

Thanks, that helped a lot! I just started studying examples and tutorials and had the same problem: parent object wasn't destroyed.

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

21 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

Related Questions

Collision between 2 prefabs. 0 Answers

How to destroy bullet on collision! 2 Answers

Collision with a coin 0 Answers

OnCollisionEnter Stopped Working 1 Answer

How to only delete one of two collided objects? 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