onMouseClick not working

Hello,

I’m just starting to program in Unity and unfortunately I’ve already ran into a problem :(.

I am trying to add a sprite and make a Debug message pop up when you click on it. I created a sprite, added a 2D box collider component and created a script with a onMouseClick() function, but it did nothing. I also tried onMouseOver() which didn’t work either. I tried an alternate method using Collider2D.OverlapPoint() but that doesn’t work either (the message in my script shown below always produces false).

I suspect there I don’t quite understand how the Collider2D class works, so if someone could give me a hand it would be much appreciated.

The script I am using is :

using UnityEngine;
using System.Collections;

public class testScript : MonoBehaviour {

    public Collider2D col;

    // Use this for initialization
    void Start () {
        col = gameObject.GetComponent<Collider2D>();
    }
	
	// Update is called once per frame
	void Update () {

        if (Input.GetMouseButtonDown(0))
        {
           
            Debug.Log("Mouse Clicked");
            Debug.Log("Mouse clicked inside collider : " + col.OverlapPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y)));

        }

    }

    void onMouseOver()
    {
        Debug.Log("Mouse over sprite");
    }

    void onMouseClick()
    {
        Debug.Log("Mouse Clicked in sprite");
    }
}

It’s OnMouseDown and OnMouseOver. Capital ‘O’ in both, you also need a collider on whatever object you’re trying to click.

i googled unity sprite mouse over and got this