shell
shell

Reputation: 1937

unity3d onMouseOver not called when sprite above it

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

Answers (1)

Doh09
Doh09

Reputation: 2385

I see 2 possible solutions, they dont use OnMouseOver though..

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

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

Related Questions