Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / AI / FSM / Actions / ConsumeManaAction.cs
@Rackday Rackday on 21 Aug 2024 844 bytes Project Added
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [CreateAssetMenu(menuName = "Finite State Machine/Action/Consume Mana")]
  5. public class ConsumeManaAction : Action
  6. {
  7. public float quantity;
  8. public bool isPercentage;
  9. public override void Act(FiniteStateMachine fsm)
  10. {
  11. Mana manaBehaviour;
  12. if (fsm.target != null && fsm.target.TryGetComponent<Mana>(out manaBehaviour)) {
  13. if (manaBehaviour.mana > 0)
  14. {
  15. float value = 0;
  16. if (isPercentage)
  17. {
  18. value = manaBehaviour.mana * (quantity / 100);
  19. }
  20. else
  21. {
  22. value = quantity * Time.deltaTime;
  23. }
  24. manaBehaviour.Consume(value);
  25. }
  26. }
  27. }
  28. }