OnMouseOver

Hi boys you can help me: have I created a script that when the cursor passes above an object with trigger appear a canvas but whit is the method that I must adopt for doing for disappear it when it goes out of the trigger? Thans to all

Public Canvas mycanvas;
{
Void OnMouseOver() {
My canvas. SetActive =true
}
}

You want onmouse enter/exit, not over
Over fires over and over again while mouse over object.

Pro tip: look at the docs Unity - Scripting API: MonoBehaviour

It’s OnMouseExit()

little late

He needs both, OnMouseEnter to SetActive(true) and OnMouseExit to SetActive(false)

Thank to all guys

You can alternatively send a ray out from the mouses position relative to the camera.

1 Like

This is imho way better, i never use the OnMouseBlah that mono has.

If so, what about telling @Timoty75 (and us) how to do that? :slight_smile:

It’s doesn’t really matter in small scale projects and using the OnMouse is alot more begginer friendly.

the way you do is is cast a ray from the mouse screen position, look at what you hit and have you own logic from there.
the reason is not having scripts on many objects in the scene, as LOTR said, one to rule them all :wink:

Thanks to all guys!