Search Unity

OnMouseDown problem when childing an object

Discussion in '2D' started by Vandarthul, Nov 26, 2013.

  1. Vandarthul

    Vandarthul

    Joined:
    Dec 23, 2012
    Posts:
    20
    Hello, so I've been trying to get the coordinates of the mouse within the object.
    Code (csharp):
    1. void OnMouseDown () {
    2.         print(Input.mousePosition);
    3.     }
    This simply works normally. But when I make this object a child of some other object and it suddently stops working. For example I have an gameObject called front, It has BoxCollider2D and the script attached. I click to the object and I see my mousePosition but when I take this object and make child of another object it stops giving me the mousePosition. I try it with the 3D Box Collider and It works regardless of childing. Is this a bug or am I doing something wrong?

    Edit: I found a solution but still, it's weird that 3d Box Collider returns the value and 2d doesn't.
    Solution: http://forum.unity3d.com/threads/29228-OnMouseDown()-Child-Colliders-issue-solved
     
    Last edited: Nov 26, 2013