- Home /
Question by
MSachs · Nov 15, 2018 at 11:37 AM ·
raycastcollideronmouseover
Calling OnMouseOver from a script on multiple colliders?
Hi,
is it possible to call multiple OnMouseOver functions from a script referring to different colliders?
So it would basically be something like this:
"OnMouseOverCollider1 - do this"
"OnMouseOverCollider2 - do that"
Or is something like that only possible with a Raycast?
Thanks in advance :)
Comment
Best Answer
Answer by dan_wipf · Nov 15, 2018 at 11:47 AM
i think you have to get each collider by raycast.
void OnMouseOver() {
RaycastHit hit;
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit))
{
if (hit.collider.name = "your name_1");
//do your code
if (hit.collider.name = "your name_2");
//do your code
}
}
Okay, thanks. That is probably the more elegant approach either way.