Search Unity

OnMouseOver script for a button?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Nicky, Dec 18, 2007.

  1. Nicky

    Nicky

    Joined:
    Nov 12, 2007
    Posts:
    19
    I was looking for a script that would allow the GUI texture to change when the user places the mouse over the GUI element. (Let them know it's a button)
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Code (csharp):
    1. var highlightColor : Color = Color.green;
    2. private var originalColor : Color;
    3.  
    4. function OnMouseEnter ()
    5. {
    6.      originalColor = guiTexture.color;
    7.      guiTexture.color = highlightColor;
    8. }
    9.  
    10. function OnMouseExit ()
    11. {
    12.      guiTexture.color = originalColor;
    13. }
     
  3. Nicky

    Nicky

    Joined:
    Nov 12, 2007
    Posts:
    19
    Is there a way to switch between 2 different GUI textures?
     
  4. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    This is what the docs are for :) Go to file://localhost/Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/index.html or http://unity3d.com/support/documentation/ScriptReference/index.html and search for gui texture. You can use the other variables in GUITexture the same way as daniel used guiTexture.color. Like for example guiTexture.texture.
     
  5. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Code (csharp):
    1. public var highlightTexture : Texture2D;
    2. private var originalTexture : Texture2D;
    3.  
    4. public function OnMouseEnter () : void
    5. {
    6.      originalTexture = GetComponent (typeof (GUITexture)).texture;
    7.      GetComponent (typeof (GUITexture)).texture = highlightTexture;
    8. }
    9.  
    10. public function OnMouseExit () : void
    11. {
    12.      GetComponent (typeof (GUITexture)).texture = originalTexture;
    13. }