Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

onEnterCollision2D not working when objects collide

Discussion in '2D' started by slykrooper, Jan 6, 2020.

  1. slykrooper

    slykrooper

    Joined:
    Oct 27, 2018
    Posts:
    10
    Hey! So i just recently asked a question about my objects not colliding and found out that I should be using rigidbody2D instead. After changing it I wanted to use onEnterCollision2D to tell when it hits something.

    Code (CSharp):
    1.         void onCollisionEnter2D(Collision2D collision)
    2.     {
    3.         Debug.Log("Hit");
    4.     }
    However when I attach this to my Player object, my console stays blank and nothing else happens. Ive tried changing it to

    Code (CSharp):
    1.         void onTriggerEnter2D(Collision2D collision)
    2.     {
    3.         Debug.Log("Hit");
    4.     }
    while also toggling "is Trigger" on my Player object and nothing happens still. I've attached a Boxcollider2D and a Rigidbody2D to both objects and even though they clearly collide and physics happens, the console still stays blank.

    this is a pretty close question to my last one so I apologize for somewhat asking it again, but I've watched about 10 different tutorials that all have these same exact codes working just fine.

    This is my Object

    upload_2020-1-6_1-44-23.png

    And this is my Player
    upload_2020-1-6_1-45-34.png

    Thank you so much, and if there is any more information I can provide just let me know.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,529
    slykrooper likes this.
  3. slykrooper

    slykrooper

    Joined:
    Oct 27, 2018
    Posts:
    10
    So im not gonna lie, Ive been struggling with this for about a whole day or so. I fixed the "O" and it works!! Your a great help man, I really appreciate it. Now I gotta kick myself for it being such a simple fix lol
     
    MelvMay likes this.