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 Poxican · Oct 14, 2012 at 12:10 PM · collisiondestroy

Destroying an object when it collides with another

I know this is asked often, but I have read pretty much every bit of information on this that I can find, all other Q&As, the resources page etc. and can't figure this out.

I have an object, SoundSphere, which when it collides with another object should destroy itself, as opposed to the other object.

I'm attempting to use this code, which I modified to fit my project from another Q&A, and is attached to my SoundSphere:

 function OnCollisionEnter(collision : Collision) 
 { 
     if (collision.gameObject.tag == "MonolithicShard")
 { 
 // if the hit object's name is MonolithicShard...
         Destroy(collision.gameObject); // destroy it
     }
 }

A rigidbody is attached to the SoundSphere, with a sphere collider. The MonolithicShards are tagged as such, and feature mesh colliders which are triggers.

When the SoundSpheres hit the shards they trigger a colour change in the shard, this particular script is attached to the shard. So that aspect of the collision works. I figured I could have the shard destroy the sphere, but I can't seem to get that to work either, as I can't figure out how to destroy the particular sphere that has triggered the colour change code.

Sorry for posting yet another question about this topic, but I just can't solve it. Hope I've provided enough information.

Cheers Nate

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 zillion · Oct 14, 2012 at 12:38 PM

I believe you may want OnTriggerEnter if your MonolithicShards are triggers. OnCollisionEnter will only work if both collide, which means NO triggers. Either take the trigger off the mesh colliders, or try and use OnTriggerEneter

Comment
Add comment · Show 2 · 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 Poxican · Oct 21, 2012 at 02:27 PM 0
Share

I reworked it after your advice and got it to work nicely, thanks :)

avatar image zillion · Oct 22, 2012 at 12:46 AM 0
Share

Glad to hear I could help :)

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

10 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

Related Questions

Trouble with raycast hitting a tagged object 0 Answers

How to only delete one of two collided objects? 1 Answer

Destroying all objects with a certain tag that ray cast if colliding with 0 Answers

Collision between 2 prefabs. 0 Answers

How to destroy bullet on collision! 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