UIEnergy.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using UnityEngine;
  2. using System.Collections;
  3. public class UIEnergy : MonoBehaviour
  4. {
  5. public static UIEnergy Instance { get; private set; }
  6. private float _energy;
  7. public UISlider EnergySprite;
  8. // Use this for initialization
  9. void Start ()
  10. {
  11. Instance = this;
  12. _energy = PlayerPrefs.GetFloat("_energy", 20000);
  13. // Debug.Log("e on start" + _energy);
  14. }
  15. // Update is called once per frame
  16. void Update ()
  17. {
  18. if (!InGameScriptCS.Instance.isGamePaused() && InGameScriptCS.Instance.isRace())
  19. {
  20. if (_energy > 0)
  21. {
  22. _energy -= NGUIHUDScript.Instance.iCurrentFrameScore;
  23. //Debug.Log("NGUIHUDScript.Instance.iCurrentFrameScore " + NGUIHUDScript.Instance.iCurrentFrameScore);
  24. }
  25. else if (_energy <= 0)
  26. {
  27. _energy = 0;
  28. if (!InGameScriptCS.Instance.isGamePaused())
  29. {
  30. //InGameScriptCS.Instance.PendingResurection();
  31. }
  32. }
  33. }
  34. EnergySprite.value = _energy / 20000;
  35. // Debug.Log(_energy);
  36. }
  37. public void Save()
  38. {
  39. PlayerPrefs.SetFloat("_energy", _energy);
  40. PlayerPrefs.Save();
  41. }
  42. public void Restore()
  43. {
  44. _energy = 20000;
  45. Save();
  46. }
  47. private void OnDestroy()
  48. {
  49. Save();
  50. }
  51. }