I'm trying to detect mouse click on 2D sprite on a 3D scene.
All my Sprite have a Box Collider 2D (well placed) and a script on it but hit is null all the time. I Also tried to put the Update() function on a script on GameEngine GameObject, but I got the same result.
void Update () {
if (Input.GetMouseButtonDown(0)) {
Vector2 mouse_position = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Collider2D hit = Physics2D.OverlapPoint (mouse_position);
if (hit) {
Debug.Log ("Hit" + hit.transform.name);
} else {
Debug.Log (hit);
}
}
}
void OnMouseDown() {
Debug.Log ("Hit " + this.name);
}