Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OnMouseEnter Confusion

Discussion in 'Editor & General Support' started by lgoss007, Dec 15, 2006.

  1. lgoss007

    lgoss007

    Joined:
    Dec 6, 2006
    Posts:
    88
    I have a script which changes the text color of a GUI Text when the mouse enters and exits (full script)

    Code (csharp):
    1.  
    2. var normalColor = Color.white;
    3. var hoverColor = Color.white;
    4. var pressedColor = Color.white;
    5. var message = "Message to send";
    6.  
    7. private var isPressed = false;
    8.  
    9. function Awake ()
    10. {
    11.     guiText.material.color = normalColor;  
    12. }
    13.  
    14. function OnMouseEnter ()
    15. {
    16.     if (isPressed)
    17.         guiText.material.color = pressedColor;
    18.     else
    19.         guiText.material.color = hoverColor;
    20. }
    21.  
    22. function OnMouseExit ()
    23. {
    24.     guiText.material.color = normalColor;
    25. }
    26.  
    27. function OnMouseUp ()
    28. {
    29.     isPressed = false;
    30.  
    31.     if (guiElement.HitTest(Input.mousePosition))
    32.     {
    33.         var controller : GameController = FindObjectOfType(GameController);
    34.         controller.SendMessage(message);
    35.     }
    36. }
    37.  
    38. function OnMouseDown ()
    39. {
    40.     isPressed = true;
    41.  
    42.     guiText.material.color = pressedColor;
    43. }
    44.  
    The confusion is that this script is attached to three seperate GUI Text objects and works correctly in the "Game View" screen. But when I do "Build And Run", the 1st object doesn't highlight if you mouse over it. But if you mouse over the third object, the first object highlights as well. However the button actions work correctly (OnMouseUp sends the correct message). Anyone have any idea what's going on? I've changed the script and saved after already attaching it to a GUI Text, would that affect it? I just don't know why it works in the preview but in the compiled game it's different.
     
  2. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Maybe if you duplicated yr script so you have 3 identical w different names and applied 1 to each button?
    AC
     
  3. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    I can't recreate your problem :( Your script works perfectly for me in both the Game view and when I build a web player and an OS X PPC stand alone.
     
  4. lgoss007

    lgoss007

    Joined:
    Dec 6, 2006
    Posts:
    88
    Hmm, tried removing the scripts from the text objects and created 2 new scripts with the same text. Saved them as TextButton, TextButton2, TextButton3 and added a seperate script to each object. Game View still shows ok, but Build and Run now highlights when hovering over the first and also highlights the second. And now the second doesn't highlight, but the third is normal. I even tried doing different builds.

    Thanks for testing. I tried Universal, Web Player, and Intel and they all do the same thing. Must be some problem with my scene file or the objects. I'll just recreate them and see if it helps.
     
  5. lgoss007

    lgoss007

    Joined:
    Dec 6, 2006
    Posts:
    88
    Tried creating a new project... same issue. Tried using a prefab... same issue. I'm guessing this might be a bug? It runs perfectly in the "Game View". Suppose I'll submit a bug report.
     
  6. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    Is it possible you have an issue similar to this one?
     
  7. lgoss007

    lgoss007

    Joined:
    Dec 6, 2006
    Posts:
    88
    :eek:

    Could very well be. I have a Radeon X1900. Of course I'm not really shocked that an ATI card has OpenGL problems and I've always wondered why Apple uses their cards (though Apple does write the drivers). I wish Apple would be quicker at fixing these driver bugs (I've had driver bugs in a different game engine with problems on framebuffer objects).