Skip to main content
added 106 characters in body
Source Link
dimitris93
  • 1.3k
  • 2
  • 16
  • 27

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.

1

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]).

enter image description here

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.)

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.

1

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]).

enter image description here

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 ?

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.

1

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]).

enter image description here

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.)

added 51 characters in body
Source Link
dimitris93
  • 1.3k
  • 2
  • 16
  • 27

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.

1

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]).

enter image description here

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 ?

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.

1

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]).

enter image description here

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 ?

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.

1

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]).

enter image description here

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 ?

added 2 characters in body
Source Link
dimitris93
  • 1.3k
  • 2
  • 16
  • 27

I have 2 objects, both have a Box collider 2D.

The first object is on the "Level1"Level1 Sorting Layer and has a Tile scriptTile script attached to it.

The second object is on the "Level0"Level0 Sorting Layer and doesn't have any scripts.

1 31

The Tile scriptTile 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]).

2enter image description here

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 ?

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.

1 3

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]).

2

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 ?

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.

1

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]).

enter image description here

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 ?

added 2 characters in body
Source Link
dimitris93
  • 1.3k
  • 2
  • 16
  • 27
Loading
edited title
Link
dimitris93
  • 1.3k
  • 2
  • 16
  • 27
Loading
added 26 characters in body
Source Link
dimitris93
  • 1.3k
  • 2
  • 16
  • 27
Loading
Source Link
dimitris93
  • 1.3k
  • 2
  • 16
  • 27
Loading