using UnityEngine; using System.Collections; /// /// 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 /// public class ButtonWithTwoStates : MonoBehaviour { GameObject normal, pressed; //public bool LevelButton; private BoxCollider _colider; public bool Toggle; public bool StartMenu; void Awake() { _colider = GetComponent(); 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; } }