Search Unity

OnMouseExit and OnMouseDown Question

Discussion in 'Scripting' started by kfrench16, Feb 11, 2010.

  1. kfrench16

    kfrench16

    Joined:
    Mar 22, 2009
    Posts:
    73
    I have attached a script to a gameobject with OnMouseOver and OnMouseExit functions. The OnMouseOver fires.

    However, about 1 or 2 seconds later the OnMouseExit function fires even though I have not moved the mouse.

    I have no gamepads or joysticks that might interfere currently hooked up.

    Is this working correctly? Would this interfere with the OnMouseDown function not to fire?

    EDIT: I've been playing with this some more. It seems after a few milliseconds, the mouse is no longer registered as being over the object. Everything works as expected when the scene first fires up. A few seconds later and OnMouseOver goes screwy.
     
  2. Jokerminator

    Jokerminator

    Joined:
    Jun 30, 2006
    Posts:
    258
    Can you post the code you are using here ?
     
  3. kfrench16

    kfrench16

    Joined:
    Mar 22, 2009
    Posts:
    73
    Yep. It'll have to wait until I get home from work though.
     
  4. kfrench16

    kfrench16

    Joined:
    Mar 22, 2009
    Posts:
    73
    It seems I am having problems with Input.GetMouseButtonDown or Up as well. They are acting "slugishly" for lack of a better term. Everything works fine the first few seconds of the scene and then it is hit or miss if the mouse down or up is registered.

    If I use just GetMouseButton, everything works although I'll get half a dozen registrations of the event in an Update function (which I expected).

    I was using the Inputs using Raycast with the following code:
    Code (csharp):
    1.  
    2.  if (Input.GetMouseButtonUp(1)) {
    3.      ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    4.        
    5.        
    6.         if (Physics.Raycast(ray, hit))
    7.         {
    8.             if (hit.collider != null)
    9.             {
    10.                 if(hit.collider.gameObject.GetComponent(enemyInfo) != null)
    11.                 {
    12.                                         print("hit");
    13.                                 }
    14.             }
    15.                     }
    16.         else
    17.         {
    18.             print("Hit nothing");
    19.         }
    20.     }
    21.  
    I'm not sure if it is my machine or if I am using the function incorrectly. Any thoughts? Please note: I have ray and hit declared at the beginning of the script.
     
  5. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Have you definitely got a collider on the object the raycast is supposed to detect?
     
  6. kfrench16

    kfrench16

    Joined:
    Mar 22, 2009
    Posts:
    73
    Yep.

    I played around some more with this last night. I used the Input.GetMouseButton(0) and got a hit with no problems.

    Using the same function with a boolean to hold true when held and false when not, that is when I noticed the intermittent hits. I assume the mousebuttonup/down work the same way.

    Does this event fire every frame while the button is held?

    I did notice some older threads on the forum with similar problems that were never resolved (at least on the forums).

    Machine specs if it helps
    Windows 7
    i7 920
    6gb ram
    Radeon 4850
     
  7. Jokerminator

    Jokerminator

    Joined:
    Jun 30, 2006
    Posts:
    258
    GetMouseButton is fired as long as you hold down the mouse button every frame. GetMouseButtonUp/Down is only fired once when you press down or release the mouse button.
     
unityunity