I have 2 objects, both have a Box collider 2D.
The first object is on the Level1
Sorting Layer and has a Tile script
attached to it.
The second object is on the Level0
Sorting Layer and doesn't have any scripts.
The Tile script
code is as follows:
void OnMouseDown()
{
Debug.Log(Input.mousePosition.ToString());
}
Whenever I click the top tile, nothing prints in the console unless I click on the red area like I show in the image below (red area = [first box collider] minus [the two box colliders intersection area]).
Why this happens ? Why doesn't the OnMouseDown()
function fire up simply when you click on its collider, since the top tile is on a higher sorting layer than the bottom tile. How does this work ? Doesn't sorting layer affect the 2D box collider ? (If I change the Z-axis of the top tile to -1, while keeping the bottom tile to 0, it works as expected.)