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 thenachotech1113 · Oct 27, 2013 at 05:16 PM · collisiononcollisionentertags

OnCollisionEneter() does nothing C sharp

hey, im trying to make it so when an object its created anything colliding with it, incouding stuff inside if it are stored in a variable. anyway, i cant even make it so it shows a message when it collides. here is the script im using

 using UnityEngine;
 using System.Collections;
 
 public class generatorScript : MonoBehaviour {
 
 
     
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     void OnCollisionEnter (Collision collision) {
             Debug.Log("Something is there");
             if (collision.transform.tag =="Base"){
                 Debug.Log("structure:" + collision.transform.name);
                 Transform structureLink = collision.transform;        
             }    
     }
 }
     

the part that i do not understand is that the objetct to wich this script is attacked is in contact with 3 other objects, anyway when i play the game absolutely nopthing happens. any help is much apreciated.

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 Zamaroth · Oct 27, 2013 at 08:27 PM 0
Share

If you want to detect a collision: Both of the objects which are colliding must have colliders enabled, can´t have IsTrigger set to true and at least one of them must have rigidbody component which doesn´t have $$anonymous$$inematic option set to true. Do your objects fulfill these things?

avatar image thenachotech1113 · Oct 28, 2013 at 12:10 AM 0
Share

yea, tho im using an oler version of unity cuz im to layzy to update. could it be a bug?

avatar image hdgam3r · Oct 28, 2013 at 12:49 AM 0
Share

Are you sure that the objects you want to compare have a layer that allow them to collide?

avatar image Josh707 · Oct 28, 2013 at 01:29 AM 0
Share

I'm not sure exactly but OnCollisionEnter probably only registers those collisions after it moves after being created, or if it is created with objects inside it it probably won't check those until they're apart and then together again.

The best option is just to use Physics.OverlapSphere(), it does exactly what you're doing and you can run it in the start funfction.

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

Why is my OnCollisionEnter function working for enemies and not my player? 1 Answer

On Trigger Enter, Collide with object, specific collision 1 Answer

Collisions and Lists 1 Answer

Collision Only being detected on one of the objects involved in the collision - C# 0 Answers

Colliding two GameObjects 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