Need Help with 2D collision Detection.

I’m trying to create a simple health system by using an integer that is lowered every collision then, have the GameManager check the int and if it is 0 or under reset the scene. My trouble comes from detecting any collision to begin with. I’ve never done a health system before, and in my game any collision on the player will be damage.

void OnCollisonEnter2D(Collision collision)
    {
        if (collision.gameObject.name == "FollowEnemy")
        {

            HitPoint -= Damage;
            Debug.Log("Damaged");
        }
    }

I know that the Object name is correct.

Spelling and capitalization are CRITICAL in programming.

Please review your spelling of the function name above.

Further of even more critical importance is typing. The actual function does not take the argument type you are specifying. It takes one related to 2D collisions.

Full docs here:

Yup, it’s always a spelling mistake that i’m always overlooking.
Thanks

It’s not free, but Rider editor will prevent these mistakes as it knows all the Unity callback functions and their signatures.
Or simply be sure to triple check spelling and arguments with the docs when ever typing callback functions.

So does Visual Studio. It write all the Unity functions automatically. The typo in the script line the op posted should not have happened in the op knew how to use Visual Studio.

Speaking of, anyone knows why unity didn’t go for OOP virtual methods model instead of magic functions?

Never presume? Ironic.

Just stating the obvious.