I want an easy way to click the top gameObject of two overlapping gameObjects
-2D only please-
Example: Two clickable 2D objects overlap, gameObject A (top) and gameObject B (bottom). gameObject A has a higher z-axis and is visibly on top, but only gameObject B is clickable. Object A is higher but only B ic clickable. B was there first and is the Background of my scene.
I’ve seen a similar question here,
but I do not want a huge work-around involving Raycast/Linecast.
I appreciate your work-arounds, but Clicking a gameobject that is on top, is the most basic concept in computer gaming and I have hard believing that Unity does not have a straight forward answer to this.
Are you shure, that your Objects have different z-axis when game is running? (Maybe z-axis is overwritten)
Do you use 2d BoxCollider? Try with 3d BoxCollider!
When Object B’s BoxCollider is setted off, does Object A’s BoxCollider trigger?
I have several GameObjects flying through the Screen, each of them need to be adjusted on z-axis automatically depending on which was clicked, and without any problems I have following Components with different configs:
-Transform-Position: Z-Axis = -1, -1.1, -1.2, etc and -2 to bring those to the front (top)
-BoxCollider (not BoxCollider 2D!!!)
Thats all I have attached.
I remember I had some issue with BoxCollider 2D, so I decided to use BoxCollider.
I hope it was usefull.
Good Luck @isteffy