Collider Problems - C#

Hello! I have encountered lots of problems with colliders in Unity. I have a 2D project and I want a object to act upon touching or, colliding. I am just testing to see if it does anything, and the code that I have is correct; I have confirmed it with many sources and books. It doesn’t seem to do anything though. I have created its own script for itself so it shouldn’t be because of the code. Here is the code that I have:

void OnTriggerEnter(Collider other){
        Debug.Log ("This better work.");
        if(other.gameObject.tag == "Player"){
            CoinFall.Touching = true;
        }
    }

Why is this not working? They are in the same z plane and they are touching each other, though it never responds.

Help?

Thanks!

-Jack

if you are using 2D system from Unity, then there is a bunch of twins for 3D classes.
Such as BoxCollider2D , CircleCollider2D , HingeJoint2D and so on.
And you are supposed to use them with 2D objects.

If you’re using 2D colliders, you need to use Unity - Scripting API: MonoBehaviour.OnTriggerEnter2D(Collider2D) instead of OnTriggerEnter, which is for 3D colliders.

1 Like

THANK YOU SO MUCH! I have had this problem for quite awhile, causing this project to go onto the backburner; thanks! It fixed all of my problems.