Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UIToggleButton : MonoBehaviour
- {
- public UISprite target;
- public string onSprite;
- public string offSprite;
- public bool isOn = false;
- void Start ()
- {
- if (target == null) target = GetComponentInChildren<UISprite>();
- }
- void OnClick ()
- {
- if (target != null)
- {
- isOn = !isOn;
- target.spriteName = isOn ? onSprite : offSprite;
- }
- }
- //This is not a callback, is only used by the WeaponSwitchHud and InputManagerGame components
- public void Switch(bool on)
- {
- isOn = on;
- target.spriteName = isOn ? onSprite : offSprite;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement