- Home /
what is the best way to detect if an object has been clicked on?
i have one main script which uses raycasts to do various actions depending on what object is clicked on. currently the objects you click on either have box or mesh colliders but these are very unreliable at picking up the click, or you have to be very specific where abouts you click on a large object.
any help would be appreciated, thank you
Well, Raycasts are usually very reliable. Are you sure you have your colliders set up properly? Are there other things interfering with them?
You could always add a trigger collider thats larger then your actual objects, and then ray cast against those triggers ins$$anonymous$$d of the actual colliders.
Answer by portchris · Nov 10, 2011 at 07:52 PM
Are you sure you have colliders setup? Why would a collider be unreliable at detecting a collision? That is effectively what you are doing with the raycast, sending out an invisible line and running a response dependant on what/if it hits. But there many ways to do this; through a RaycastHit or Debug.Log().
thankyou for replying the game is about clicking on different objects which are in close proximity of each other but they are all separate meshes. they are all tagged and all have mesh colliders. some detect the click easily and others you have to be very specific where you click. does camera angle have any effect on this? i have changed a couple to box colliders as this seems to be more effective on them. but others are not detecting the click at all.
You should try looking at exactly where your colliders are going. I suspect that part of the problem is that a lot of them are interfering with each other, and one in front will stop the raycast from hitting the ones behind it.