Why doesn't it register?

Hi, I am creating pong and I have ran into a problem. I want to keep score and the way I thought about doing it would be to create a score script, add it to both the left and right walls and then using the OnCollisionEnter2D functions, check to see if the Ball object has hit it, if so, do something. This doesn’t seemed to have worked and I am not sure why. You can ignore score for now, just wondering why the Debug.Log isn’t actually doing anything, or more so, the collision.

using UnityEngine;
using System.Collections;

public class Score : MonoBehaviour
{
    public int score = 0;

    void onCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.name == "Ball")
        {
            score = score + 1;
            Debug.Log("Hit");
        }
    }
}

I am a complete beginner when it comes to Unity scripting but I have some previous knowledge of C#. Any mistakes not related to the actual issue are welcome to be pointed out :slight_smile:

thanks.

Capitalize the O in OnCollisionEnter2D

Kelso said it :slight_smile:

Oh my god. I am so stupid.

Well, good to know it isn’t that big of an error.

It’s alright to make mistakes while you’re learning.

1 Like