UIEnergyController.cs 773 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using UnityEngine;
  3. [ExecuteInEditMode]
  4. public class UIEnergyController : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. }
  9. private void Update()
  10. {
  11. if (this.EnergyValue > this.EnergyMaxValue)
  12. {
  13. this.EnergyValue = this.EnergyMaxValue;
  14. }
  15. for (int i = 0; i < this.energyItems.Length; i++)
  16. {
  17. this.energyItems[i].enabled = (i < this.EnergyValue);
  18. }
  19. for (int j = 0; j < this.energyGroup.Length; j++)
  20. {
  21. this.energyGroup[j].enabled = (j < this.EnergyMaxValue / 2);
  22. }
  23. }
  24. [Range(0f, 20f)]
  25. [SerializeField]
  26. public int EnergyValue;
  27. [SerializeField]
  28. [Range(6f, 20f)]
  29. public int EnergyMaxValue;
  30. [SerializeField]
  31. private UISprite[] energyItems;
  32. [SerializeField]
  33. private UISprite[] energyGroup;
  34. }