ToggleButton

From Unify Community Wiki
Revision as of 10:54, 9 December 2005 by KeliHlodversson (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


<csharp> using UnityEngine; using System.Collections;

[AddComponentMenu ("GUI/Toggle Button")] public class ToggleButton : Button {

   public ButtonTextures selectedTextures;
   public bool selected=false;
   protected override void SetButtonTexture(ButtonState state) {
       ButtonTextures textureSet=selected?selectedTextures:textures;
       switch(state) {
           case ButtonState.normal:
               myGUITexture.texture=textureSet.normal;
               break;
           case ButtonState.hover:
               myGUITexture.texture=textureSet.hover;
               break;
           case ButtonState.armed:
               myGUITexture.texture=textureSet.armed;
               break; 
       }
   }
   
   public override void Reset() {
       selected=false;
       base.Reset();
   }
   
   public override void OnMouseUp()
   {
       
       if (state == 2)
           selected = !selected;
       
       base.OnMouseUp();
   }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox