How do i click on a 3d object?

Hi guys,

im only new so go easy :stuck_out_tongue:

i have a box that opens upon a left mouse click, however it opens even when my mouse is off my object, how can i attach it to my main 3D object only?

this is the code i have so far:

function playMe () {
 
     animation.Play("open");
}



function OnGUI() {
    var e : Event = Event.current;
    if(e.button == 0  e.isMouse){
        Debug.Log("Left Click");
      
        playMe();
    } 
}

please help, ive been tearing my hair out for hours!!

You need to shoot a ray. Look down this page for the last but one example:

Use OnMouseDown.

–Eric