- Home /
Detect mouse over without rigidbody... Using Raycast maybe?
I've a GameObejct which looks like a cube... attached to it many other smaller gameobjects on it's surface...I want to show the name of any of those smaller gameobjects whenever I hover the mouse over them... Any suggestions ? :)
P.S: I can't use Colliders because the cube collider is bigger than any of the smaller gameobjects colliders... so they are contained in it... that's why it won't detect any mouse over using a collider and a rigidbody.
Why not create a script that specifically monitors On$$anonymous$$ouseEnter (and maybe On$$anonymous$$ouseLeave, as your needs dictate)?
I posted a similar solution for detecting clicks a while back.
Basically, you make a script that is only about detecting the mouse events you want and publishing them as events, then you trap the events and handle them as needed.
In your case, you might even write a specific script that traps On$$anonymous$$ouseEnter, publishes the name of the current cube to some well-known location, then traps On$$anonymous$$ouseLeave and clears the name.
Sir the problem is I can't detect whether the mouse entered or not.
Yeah. I see that it's because you have a larger collider that can block the signal.
There might be something here: https://docs.unity3d.com/$$anonymous$$anual/LayerBasedCollision.html
...but I'm guessing that this is a better bet: https://answers.unity.com/questions/392601/onmouseenter-through-colliders.html
Answer by Darkforge317 · Nov 28, 2017 at 07:10 PM
I would still keep colliders on the smaller objects. Just use Physics.RaycastAll
It will collect all objects that the Ray passes through, then you can simply display the name of the last object it hits.
That way it'll hit the big cube, store it in the array, and then hit one of the objects inside of it, and store that in the array as well. Just look at the last object in the array and display its name.
Your answer helped me achieve my desired result ^_^ Thanks a lot ♥
Answer by $$anonymous$$ · Nov 28, 2017 at 07:03 PM
Can you share a print of your screen? Will help find a solution.
Your answer
Follow this Question
Related Questions
Destroy Objects to Load New Scene 3 Answers
How to detect mouse click on sprite? 2 Answers
Click on Arrows to Move Object. 1 Answer
Display material options menu on click 0 Answers
Select something using mouseclick 2 Answers