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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

OnTriggerEnter2D not working

Discussion in 'Getting Started' started by Drowzee, Jul 30, 2017.

  1. Drowzee

    Drowzee

    Joined:
    Aug 16, 2015
    Posts:
    27
    I have this code:
    Code (CSharp):
    1. void OnTrigger2D(Collider2D other)
    2.     {
    3.         if(other.gameObject.name == "Mouse")
    4.         {
    5.             Debug.Log("Meoew");
    6.         }
    7.     }
    which returns no errors and looks right to me, yet no matter what I try the debug lof wont print. ive tried using OnCollisionEnter2D as well, I've tried making both objects triggers, ive tried making only one a trigger, heck ive tried making none of them triggers. I've added and removed the RigidBodies from both, I have no idea why this wont work.

    Any insight?
     
  2. Drowzee

    Drowzee

    Joined:
    Aug 16, 2015
    Posts:
    27
    I fixed this by putting the function onto the other colliding object, idk why this fixed it but it did.