Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Mouse Events

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

  1. Kalmak


    Nov 15, 2008
    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


    Jul 16, 2006
    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.