Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
ScreenPointToRay look handy, thanks! what dows the out keyword do ? –  George Profenza Oct 7 '10 at 19:55
    

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.