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 /
avatar image
0
Question by SonicDirewolf · Oct 10, 2018 at 06:44 PM · rigidbody2doncollisionentercollision2d

OnCollisionEnter2D isn't working

I have two objects, both of them have rigidbody2d set to dynamic and istrigger is off. Both the objects when collided on screen register the collision and do not pass through each other. But the code under the void OnCollisionEnter2D(Collision2D col) isn't working at all. The spelling is correct. Please help. I'm posting the whole code from the script. Thank you!

     public TimeManager timeManager;
     public Animator anim;
     public Animator anim1;
     
     public static Plane instance;
    
      void Awake()
     {
         if (instance == null)
         {
             instance = this;
         }
     }
  
     void Start () {
    
     }
     
     void Update () {
 
         if (Input.GetButton("Fire1"))
             {
 
             SlowTime();
   
         }
  
     }
 
    void SlowTime()
     {
         timeManager.SlowMotion();
 
     }
 
 
     void OnCollisionEnter2D(Collision2D col)
     {
 
         if (col.gameObject.tag == "Bullet")
         {
             anim.SetTrigger("Hurt");
             anim1.SetTrigger("KnockBack");
             Debug.Log("Hello");
 
         }
 
     }
 
 
 }
 
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 Casiell · Oct 10, 2018 at 08:05 PM 0
Share

Put some debug above the tag check, that's the most likely culprit right now.

avatar image SonicDirewolf Casiell · Oct 11, 2018 at 01:59 PM 0
Share

I've added the debug above the tag check but it still doesn't work

avatar image Casiell SonicDirewolf · Oct 11, 2018 at 02:10 PM 0
Share

So you setup your game objects wrong. Please upload screens of hierarchy of both objects that are supposed to collide

Show more comments

1 Reply

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

Answer by SonicDirewolf · Oct 11, 2018 at 02:14 PM

I just figured it out. It was very stupid of me. The object with the code and the object with the box collider were different but under the same parent. I added the box collider to the object with the script and it's working great now. Thank you so much for your time!

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

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

Related Questions

HOW TO CALLBACK COLLIDER WITH NAME? 2 Answers

OnCollisionEnter2D Problems in Unity 4.5 1 Answer

OnCollisionEnter2D and OnCollisionExit2D issue 1 Answer

More realistic physics on child collisions 2D 0 Answers

Buggy touch controls? 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