1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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();
- }
- }
|