Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Mana.cs
@Rackday Rackday on 21 Aug 846 bytes Project Added
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Events;
  6. public class Mana : MonoBehaviour
  7. {
  8. public float mana = 100;
  9. [SerializeField] private float regenRate;
  10. public bool instaRegen;
  11. public float maxMana = 100;
  12. public UnityEvent<float> onManaUpdated;
  13. void Update()
  14. {
  15. if (mana < maxMana)
  16. {
  17. float v = regenRate * Time.deltaTime;
  18. mana += v;
  19. onManaUpdated.Invoke(v);
  20. }
  21. if (mana > maxMana)
  22. {
  23. mana = maxMana;
  24. }
  25. if (mana < 0) mana = 0;
  26. if (instaRegen)
  27. {
  28. mana = maxMana;
  29. }
  30. }
  31. public void Consume(float cost)
  32. {
  33. mana -= cost;
  34. onManaUpdated.Invoke(-cost);
  35. }
  36. }