- Home /
Texture-based mouseclick detection
Hi all, I'm making a little game where you have to click on moving objects to destroy them.
I also have a crosshair texture (attached to an empty gameobject) following my mouse movement.
Right now I handle click detection by implementing an OnMouseDown handler in my moving gameobject. The problem with this, however, is that when I click just on the edge of an object, the click misses, while the object was actually inside boundaries of the crosshair.
Is there any way I can detect if the texture overlaps a gameObject?
You can try to use Camera.ScreenPointToRay. Do this four times for every corner of your crosshait texture. You will need to make something up for the case that multiple objects get hit.
Answer by Julian_Spring · Mar 06, 2013 at 06:46 PM
Do you have a collider on the object?
And can you post your script?