Forum begins after the advertisement:
[Part 4] Mana is spent even without healing
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 4] Mana is spent even without healing
- This topic has 0 replies, 2 voices, and was last updated 6 days ago by
Ser Apustaja.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
June 15, 2025 at 10:01 pm #18315::
Reposting @stephanvieira3665‘s question from YouTube:
Hello, if i only have a little a bit of mana, not enough to heal 1x Health, it still drains all the mana. Have you found any fixes for this? Thanks!
void Heal() { if (Input.GetButton("Healing") && Health < maxHealth && Mana > 0 && Grounded() && !pState.dashing) { 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; } }
June 15, 2025 at 10:10 pm #18316::To address the issue where the
Heal
function drains all mana even when there isn’t enough to heal a full health point, you can add a check to ensure that the mana cost for healing does not exceed the available mana. Here’s a modified version of yourHeal
function:void Heal() { if (Input.GetButton("Healing") && Health 0 && Grounded() && !pState.dashing) { pState.healing = true; anim.SetBool("Healing", true); // Check if enough mana is available for healing float manaCost = Time.deltaTime * manaDrainSpeed; if (Mana >= manaCost) { // healing healTimer += Time.deltaTime; if (healTimer >= timeToHeal) { Health++; healTimer = 0; } // drain mana Mana -= manaCost; } else { // Not enough mana to heal, stop healing pState.healing = false; anim.SetBool("Healing", false); healTimer = 0; } } else { pState.healing = false; anim.SetBool("Healing", false); healTimer = 0; } }
Changes Made:
- Mana Check: Before draining mana, the code checks if the current mana is greater than or equal to the cost of healing (
manaCost
). - Stop Healing: If there’s not enough mana, the healing state is reset, and the animation is stopped.
This way, the healing will only continue if there is sufficient mana to support it, preventing the drain of all the mana when it’s insufficient.
- Mana Check: Before draining mana, the code checks if the current mana is greater than or equal to the cost of healing (
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
Advertisement below: