using UnityEngine; using System.Collections; public class UIEnergy : MonoBehaviour { public static UIEnergy Instance { get; private set; } private float _energy; public UISlider EnergySprite; // Use this for initialization void Start () { Instance = this; _energy = PlayerPrefs.GetFloat("_energy", 20000); // Debug.Log("e on start" + _energy); } // Update is called once per frame void Update () { if (!InGameScriptCS.Instance.isGamePaused() && InGameScriptCS.Instance.isRace()) { if (_energy > 0) { _energy -= NGUIHUDScript.Instance.iCurrentFrameScore; //Debug.Log("NGUIHUDScript.Instance.iCurrentFrameScore " + NGUIHUDScript.Instance.iCurrentFrameScore); } else if (_energy <= 0) { _energy = 0; if (!InGameScriptCS.Instance.isGamePaused()) { //InGameScriptCS.Instance.PendingResurection(); } } } EnergySprite.value = _energy / 20000; // Debug.Log(_energy); } public void Save() { PlayerPrefs.SetFloat("_energy", _energy); PlayerPrefs.Save(); } public void Restore() { _energy = 20000; Save(); } private void OnDestroy() { Save(); } }