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 RGI · Feb 27, 2013 at 12:32 PM · javascriptcollisionprefabprefabsoncollisionenter

Cannot remove a prefab using OnCollisionEnter function.

Hi, I have a set of spawners generating prefabs randomly and an object below that is supposed to remove the prefab when it collides with it. This is the script Iam using:

    function OnCollisionEnter ( collision : Collision){
       if (collision.gameObject.name == "Coin(Clone)"){
         Destroy(collision.gameObject);}
         }

Both objects have box colliders enabled, I've tried changing "is trigger", changing the name of the object (coin, coin(Clone)), tried to change the script by adding transform variable and detecting collision with a prefab directly instead of the name but it is still not removing the prefabs. What am I missing?

Comment
Add comment · Show 4
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 MickM · Feb 27, 2013 at 01:29 PM 0
Share

Have you tried using tags?

avatar image RGI · Feb 27, 2013 at 09:19 PM 0
Share

yes, I even tried using variables and stuff, the problems isnt there..

avatar image MickM · Feb 27, 2013 at 10:08 PM 0
Share

Put in a debug.log statement at different spots through the code so you can work out where it gets to... That will help work out what is wrong. The code itself should work

avatar image RGI · Feb 28, 2013 at 06:52 PM 0
Share

Seems like there is no collision at all..

1 Reply

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

Answer by steakpinball · Feb 27, 2013 at 02:01 PM

Moving objects typically need to have a rigid body attached for collisions to occur. Check the collision matrix on http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html to verify whether it is needed.

And I suggest using tags to identify objects in this manner.

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 RGI · Feb 27, 2013 at 06:33 PM 0
Share

Adding rigid body to either od the objects is not helping. Nor is the tag identifying..

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

11 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

Related Questions

Destroy a GameObject 2 Answers

Checking to see if two objects are colliding. 2 Answers

Emit Particle on Collision Issue 0 Answers

How can I make my truck drive on terrain and on bridge 1 Answer

How to instantiate on collision? 0 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