- Home /
Answer by SharkoFR · May 03, 2018 at 01:44 PM
Use RayCast Hit!
wiki: https://docs.unity3d.com/ScriptReference/RaycastHit.html
tuto: https://www.youtube.com/watch?v=6agwCUaMNWI (i'm not the owner of the tuto)
Answer by no00ob · May 03, 2018 at 01:32 PM
That OnMouseOver will probably work as PeteZa94 suggested, but I'd personally prefer Ray casting.
On$$anonymous$$ouseOver
actually also works with raycast, it is just hidden within the event system. That is why it only works for objects that have a collider.
Answer by PeteZa94 · May 02, 2018 at 03:39 PM
Depends on the type of game you're making, but you could try to use the OnMouseOver function.
void OnMouseOver(){
Debug.Log("The player is looking at " + transform.name);
}
If you attach this script to an object, it will print out it's name when your mouse is over it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612161917im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trigger and raycast error? 2 Answers
Unity android screen resolution 1 Answer
Click/Touch on Different part of sprite detected ? 0 Answers
Help with LineRenderer 1 Answer
RayCast Boolean Help 1 Answer