4
\$\begingroup\$

I've just started to learn Unity3D.

I want to create a simple 3D menu with just two 3D Text instances. I've created and named them, then dropped this script:

function Awake(){
    print("MenuItem "+gameObject.name+" init!");
}
function OnMouseEnter(){
    print("OnMouseEnter " + gameObject.name);
}
function OnMouseDown(){
    print("OnMouseDown " + gameObject.name);
}

I only see the init/awake message printed in the console.

What am I missing ?

EDIT:

Sorry, I forgot to add the BoxCollider(Physics>Box Collider) to my object, so no events were triggered.

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

First make sure that everything else is set up correctly.

In a different script that's running somewhere, put in this bit of code (C#, and from memory so it may not be 100% accurate):

RaycastHit hitInfo;
if( Physics.Raycast( Camera.main.ScreenPointToRay( Input.mousePosition ), out hitInfo ) )
{
    Debug.Log( "mouse is over object " + hitInfo.collider.name );
} 

If that doesn't work then you probably don't have your colliders set up correctly. If it does print out something then you have something else messed up.

\$\endgroup\$
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .