Reputation: 1937
I have a tile based grid system where each tile has a box collider. These tiles make use of:
OnMouseOver()
Which calls correctly. However, if I have another sprite with a collider in the same position as the tile, it seems to block the tile being able to trigger OnMouseOver().
What is a good fix for this?
Upvotes: 0
Views: 712
Reputation: 2385
I see 2 possible solutions, they dont use OnMouseOver though..
Use raycasting from the screen to the mouse position, in your FixedUpdate method (as its physics based). In the raycast you can define which layers should be collided with, this allows you to determine which objects are detected.
If it doesnt work yet, another solution could be to make an invisible object which constantly in its update method sets its position to be the mouse position, then add a collider to it and set the collider as a trigger so it can move freely. Give the object the tag "Cursor" and use OnTriggerEnter as the method instead of OnMouseClick.
Upvotes: 1