Search Unity

Mouse Events

Discussion in 'Scripting' started by Kalmak, Mar 28, 2009.

  1. Kalmak

    Kalmak

    Joined:
    Nov 15, 2008
    Posts:
    52
    I have been looking at Richard Hart's Unity for Flash developers tutorials and got to section 4 on mouse events. I couldn't get the code to work so I followed the advice of my programming profs and went back to square one.

    I started a new scene and added a cube from under the GameObject Create other menu. I created a new javascript and added the following code below the Update function:

    function OnMouseEnter(){
    Debug.Log("Mouse Enter");
    }

    I saved the script file and then dropped it onto the cube.

    Having read the documentation I expected to receive a Mouse Enter message in the console when I moved the mouse over the cube. However, I get nothing.

    I checked the Debug.Log line by cutting and pasting it into the Update function and it works fine. I also tried function OnMouseDown and received no feedback either. I checked the cube and it has a box collider and isTrigger is off.

    Any idea why this isn't working. I'm sure it is something simple but I just can't seem to find it.

    BTW I am using the 2.5 demo

    Thanks a bunch for the help.
     
  2. CoherentInk

    CoherentInk

    Joined:
    Jul 16, 2006
    Posts:
    216
    My only guess would be that the cube doesn't have a collider on it, but if you created it from the menu, then it should.

    To confirm, you have nothing in your scene but a camera and a cube with the attached code? That certainly should work, but maybe you could post the project here so we can take a look at what you've done.