- Home /
OnMouseOver is not working properly?
I have objects in my scene that detect when the mouse is over their collider. All the objects are exactly the same. It works when I am close enough to the object but when it is too far away it doesn't detect the cursor. They have huge colliders on them so I don't think the problem has to do with the size of those. Any ideas for why this could be?
there is probably another collider in the scene that is getting between the camera and the On$$anonymous$$ouseOver object
how are you detecting them being over it?
On$$anonymous$$ouseOver is a GUI function not a general gameobject function.
If its custom code your going to have to post.
if its a raycast try sphere casting ins$$anonymous$$d so you get a bigger radius.
@sparkbarca I have used On$$anonymous$$ouseOver for detecting on gameobjects before and it can be quite effective in 3d menus and the like.
yea just read the docs didnt notice it worked with colliders in general as well.
are the objects your mousing over standing straight up?
maybe the angle between the mouse which is straight up and the object which may be canted makes it appear they are over eachother but when unity raycasts to check it isn't.
Close up the difference is less noticable.
When you are close up can you aim near the edge and still be over it but not get a mouseover true?
Seth was right there was another collider that i forgot about. What would be the best way to detect the mouse on an object behind another collider?
Answer by venhip · Nov 14, 2012 at 07:42 AM
Do you have your mouse locked to the centre of your screen? I've had problems with that in the past but if not then it's probably best to do a raycast or spherecast from a camera. It will give you more options later on.
http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
http://docs.unity3d.com/Documentation/ScriptReference/Physics.SphereCast.html
check there for more info on how to use them. If you want to detect for an infinite distance you can set the distance of the raycast very high, higher than you'll ever need - or perhaps someone else knows a way of carrying it on forever (might kill your cpu though)
ray cast does go on forever it is by default to the length
mathf.infinity (not infinite but yea its really big)
Your answer
Follow this Question
Related Questions
Internal collisions 1 Answer
Getting continuos collision AND collision without a barrier 0 Answers
Why does a prefab instance not collide, when prefab collisions work fine? 0 Answers
OnCollisionEnter2D is not working 0 Answers
AddTorque vs Colliders 1 Answer