Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. public class UIToggleButton : MonoBehaviour
  2. {
  3.     public UISprite target;
  4.     public string onSprite;
  5.     public string offSprite;
  6.  
  7.     public bool isOn = false;
  8.  
  9.     void Start ()
  10.     {
  11.         if (target == null) target = GetComponentInChildren<UISprite>();
  12.     }
  13.  
  14.     void OnClick ()
  15.     {
  16.         if (target != null)
  17.         {
  18.             isOn = !isOn;
  19.             target.spriteName = isOn ? onSprite : offSprite;
  20.         }
  21.     }
  22.  
  23.     //This is not a callback, is only used by the WeaponSwitchHud and InputManagerGame components
  24.     public void Switch(bool on)
  25.     {
  26.         isOn = on;
  27.         target.spriteName = isOn ? onSprite : offSprite;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement