Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by B1rdieboy · May 08, 2016 at 04:00 PM · javascriptcolliderdestroy object

If you collide with an object destroy the object updated for unity 5 ?

I am trying to make it so that when i collide with an object it destroys the objects and adds to my inventory.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Wolfrik_Creations · May 10, 2016 at 07:44 PM

To all of the unintelligent people who posted C#, read the tags and question next time. He also said when you collide with it, not when you enter a trigger.

Anyway if you're wanting it to just destroy what it has hit then do this:

 function OnCollisionEnter (col : Collision){
    Destroy(col.gameObject);
 }

but if you would like to destroy the parent then you would do this:

 function OnCollisionEnter (col : Collision){
    Destroy(col.transform.root.gameObject);
 }

now you may need to tweak some stuff instead of Destroying the object if you want to add it to your inventory, but this is different for everyone and I don't know how your inventory is set up.

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
avatar image
0

Answer by Tim0theus · May 08, 2016 at 04:29 PM

What exactly do you need? C# Code?

You could do it for example like this in a script on the player:

  void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Item"))
     {
         //.... code to add other.gameObject to inventory

         Destroy(other.gameObject);
     }
 }

The object you want to pick up, should have a collider, with "Is Trigger" on true and in this case the tag "Item".

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
avatar image
0

Answer by Dext · May 08, 2016 at 04:29 PM

 void OnTriggerEnter (Collider coll)
 {
    // Here you can Add the coll GameObject to your Inventory (perhaps a 
   //  dictionary)
    Destroy (coll.transform.gameObject);

 }
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 Unity_scat · May 08, 2016 at 04:59 PM 0
Share

@Dext

OnCollisionEnter(Collision col)

That works too!

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Destroy instatiate object on trigger enter / collision,destroy instantiate prefab on trigger enter 0 Answers

making objects react to colliders without tag C# 1 Answer

2 Rigidbodies at rest collision detection issue 1 Answer

Text disappear on OnTriggerExit() 1 Answer

GameObject not destroying on Collision 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