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 /
This question was closed Jul 22, 2014 at 06:36 PM by SeeSharp for the following reason:

I changed from 2D to 3D. Everything works fine now.

avatar image
0
Question by SeeSharp · Jul 22, 2014 at 01:58 PM · 2dnotworking

OnCollisionExit2D not getting called?

Hello, While trying to make a pretty simple game for my friend, I encountered an annoying problem. My problem is that OnCollisionExit2D just isn't getting called when my player stops touching the ground, but OnCollisionExit2D works with other objects. I've done some research, and found the common solution of adding a Rigidbody2D to the ground, but that didn't work. Here's my setup: Ground game object: Ground game object Player game object: Player game object

Player collision methods:

 void OnCollisionEnter2D (Collision2D collision)
         {
                 Debug.Log ("Enter: " + collision.gameObject.tag);
                 if (collision.gameObject.tag.Equals ("Ground")) {
                         touchingGround = true;
                 }
                 if (collision.gameObject.tag.Equals ("Obstacle")) {
                         collision.gameObject.GetComponent<ObstacleScript> ().moveObstacle = false;
                         gameOver = true;
                 }
         }
 
         void OnCollisionExit2D (Collision2D collision)
         {
                 Debug.Log ("Exit: " + collision.gameObject.tag);
                 if (collision.gameObject.tag.Equals ("Ground")) {
                         touchingGround = false;
                 }
         }

Output in console:

 Enter: Ground
 (Exit: Ground supposed to be here)
 (Enter: Ground supposed to be here)
 Enter: Obstacle

If you need any more information, please ask.

Thank you,

SeeSharp.

Comment
Add comment · Show 1
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 SeeSharp · Jul 22, 2014 at 02:03 PM 0
Share

If the images are broken for you like they are for me(I don't know why), the links are: Ground game object Player game object

1 Reply

  • Sort: 
avatar image
0

Answer by HarshadK · Jul 22, 2014 at 02:11 PM

 Check for equality using '==' operator.
 
 So the code will become:
 
 void OnCollisionEnter2D (Collision2D collision)
     {
         Debug.Log ("Enter: " + collision.gameObject.tag);
         if (collision.gameObject.tag == "Ground") {
         touchingGround = true;
     }
     if (collision.gameObject.tag == "Obstacle") {
         collision.gameObject.GetComponent<ObstacleScript> ().moveObstacle = false;
         gameOver = true;
    }
 }
  
 void OnCollisionExit2D (Collision2D collision)
     {
         Debug.Log ("Exit: " + collision.gameObject.tag);
         if (collision.gameObject.tag == "Ground") {
         touchingGround = false;
     }
 }
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 SeeSharp · Jul 22, 2014 at 02:17 PM 0
Share

Thanks for the suggestion, but that still doesn't answer my problem. OnCollisionExit2D isn't getting called, I'm not getting any Debug calls. I use .Equals() because of my Java habits, and in Java == doesn't always work when comparing strings.

I also Google'd "C# .equals vs ==" and some people stated that .equals would be more accurate as it compares the characters and not the actual object.

Thank you,

SeeSharp.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

OnTriggerEnter not working 0 Answers

Character Animation Wont Play 2 Answers

troble with the Axis in unity 1 Answer

SetColor not working? 1 Answer

MuzzleFlash not working 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