::
Hi Daikuna, this behaviour is intended.
Even if you have enough mana to fulfill the mana drain speed, it will still not heal. The healing only occurs if you heal for a duration greater than timeToHeal
. Otherwise, trying to heal will just drain your mana without healing you (like in Hollow Knight).
If you want to prevent the user from healing if he does not have enough mana to heal any health, you will have to check your current mana against the timeToHeal * manaDrainSpeed
value, like so:
void Heal()
{
bool sufficientMana = Mana < manaDrainSpeed * timeToHeal;
if (Input.GetButton("Healing") && Health < maxHealth && Mana > 0 && !pState.jumping && !pState.dashing && sufficientMana)
{
pState.healing = true;
anim.SetBool("Healing", true);
//healing
healTimer += Time.deltaTime;
if (healTimer >= timeToHeal)
{
Health++;
healTimer = 0;
}
//drain mana
Mana -= Time.deltaTime * manaDrainSpeed;
}
else
{
pState.healing = false;
anim.SetBool("Healing", false);
healTimer = 0;
}
}
Hope this helps!