12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// This component is responsible for toggling between two sprites.
- /// The sprites should be created as NGUI sprites, and should be named as follows
- /// BackgroundNormal - for the unpressed normal state
- /// BackgroundPressed - for the pressed state
- /// </summary>
- public class ButtonWithTwoStates : MonoBehaviour
- {
- GameObject normal, pressed;
- //public bool LevelButton;
- private BoxCollider _colider;
- public bool Toggle;
- public bool StartMenu;
- void Awake()
- {
- _colider = GetComponent<BoxCollider>();
- normal = transform.Find("BackgroundNormal").gameObject;
- pressed = transform.Find("BackgroundPressed").gameObject;
- DeactivateButton();
- }
- void OnPress(bool isPressed)
- {
- normal.SetActive(!isPressed);
- pressed.SetActive(isPressed);
- }
- public void OnEnable()
- {
- if (StartMenu)
- {
- //Debug.Log(PlayerPrefs.GetInt("GetCoupon"));
- if (PlayerPrefs.GetInt("GetCoupon") == 1)
- {
- ActivateButton();
- }
- else
- {
- DeactivateButton();
- }
- }
- else
- {
- //Debug.Log(PlayerPrefs.GetInt("GetCoupon"));
- if (PlayerPrefs.GetInt("GetCoupon") == 1 )
- {
- ActivateButton();
- }
- else
- {
- DeactivateButton();
- }
- }
- }
- public void DeactivateButton()
- {
- if (normal == null)
- {
- return;
- }
- normal.SetActive(false);
- pressed.SetActive(true);
- _colider.enabled = false;
- }
- public void ActivateButton()
- {
- if (normal == null)
- {
- return;
- }
- normal.SetActive(true);
- pressed.SetActive(false);
- _colider.enabled = true;
- }
-
- }
|