i’m using an Image with fill to the mana bar, and a button to subtract from the mana. i’ve also added a text on the mana bar to show the exact amount so i can adjust the numbers to get it right. I’m not sure why it won’t regenerate the mana, I hope someone can help me with this. Thank you in advance.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MoveLeftBar : MonoBehaviour
{
public Image lifeBar;
public Image manaBar;
public Text lifeText;
public Text manaText;
public float myLife;
public float myMana;
private float manaRegenAmount;
private float currentLife;
private float currentMana;
private float calculateLife;
void Start()
{
currentLife = myLife;
currentMana = myMana;
manaRegenAmount = 10f;
}
void Update()
{
calculateLife = currentLife / myLife;
lifeBar.fillAmount = Mathf.MoveTowards(lifeBar.fillAmount, calculateLife, Time.deltaTime);
lifeText.text = "" + (int)currentLife;
if (currentMana < myMana)
{
//manaBar.fillAmount += manaRegenAmount * Time.deltaTime * 0.01f;
manaBar.fillAmount = Mathf.MoveTowards(manaBar.fillAmount, 1f, Time.deltaTime * 0.01f);
currentMana = Mathf.MoveTowards(currentMana / myMana, 1f, Time.deltaTime * 0.01f) * myMana;
}
if (currentMana < 0)
{
currentMana = 0;
}
manaText.text = "" + Mathf.FloorToInt(currentMana);
if(currentLife <= 0)
{
//Instantiate
}
}
//}
public void Damage(float damage)
{
currentLife -= damage;
}
public void ReduceMana(float mana)
{
if (mana <= currentMana)
{
currentMana -= mana;
manaBar.fillAmount -= mana / myMana;
}
else
{
//not enough mana
}
}
}