Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Mana.cs
@Rackday Rackday on 21 Aug 846 bytes Project Added
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;


public class Mana : MonoBehaviour
{
    
    public float mana = 100;
    [SerializeField] private float regenRate;
    public bool instaRegen;
    public float maxMana = 100;
    public UnityEvent<float> onManaUpdated;

    void Update()
    {
        if (mana < maxMana)
        {
            float v = regenRate * Time.deltaTime;
            mana += v;
            onManaUpdated.Invoke(v);
        }
     
        if (mana > maxMana)
        {
            mana = maxMana;
        }

        if (mana < 0) mana = 0;
     
        if (instaRegen)
        {
            mana = maxMana;
        }
    }

    public void Consume(float cost)
    {
        mana -= cost;
        onManaUpdated.Invoke(-cost);
    }

   
}