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 ProgrammerWannabe · Dec 28, 2011 at 03:28 AM · collisiononcollisionentercontact

OnCollisionEnter not working

Hey

I am trying to make a simple collision detection scprit. I have tried it several times in different projects, and it seems to not work. It is written in C#, i have tried using this in various formats and it still doesnt work.

Can someone tell me whats wrong? or is it something that i must put onto my game objects? they all have box collides already.

  function OnCollisionEnter(theCollision : Collision){
 
      if(theCollision.gameObject.tag == "Player"){
       Debug.Log("Hit the Good_Fruit");
       
      }
      else Debug.Log("no collision yet !!!@@#@!$ ");
      } 
 
 

Thanks

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by adrenak · Dec 29, 2011 at 08:01 PM

Do you have a collider? If you dont have a box/sphere/mesh collider then the script wont work I guess. Here at the link below, u can see, I made a 3d model in blender called chair. I also made a model called collider and added mesh collier component to it. THen i added both of them to an empty object called officeChair,

http://imageshack.us/photo/my-images/171/chairl.jpg/

I too faced a similar problem, it worked out this way

Hope this helps

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 adrenak · Jan 08, 2012 at 02:56 AM 0
Share

To detect collisions the object for which you have this script must have rigidbody component and must be non kinematic.

avatar image yoyo · Jul 10, 2013 at 11:18 PM 0
Share

And the rigidbody must not be sleeping ...

avatar image
0

Answer by bearman · Nov 09, 2012 at 04:16 AM

This happens very rarely but sometimes, for some reason unity stops synchronizing with mono editor and even though you update the script it does not follow new lines of code, instead it keeps compiling lines that are not even there anymore. Just happened to me, even though I tried to get collisions it would not work but then I realized it was printing some debug message from a print() statement that I put on line 83, however I had deleted that print() function before I started to run the game and saved the script.

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

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

Collision with no contact? 2 Answers

Rigidbody not calling OnCollisionEnter 1 Answer

OnCollisionEnter called once even with multiple contacts 1 Answer

Objects in my scene are not responding to OnCollisionEnter 0 Answers

Using collision with Vector3.MoveTowards 3 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