Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How do I create a mana bar?

Discussion in 'Scripting' started by Deleted User, Feb 22, 2015.

  1. Deleted User

    Deleted User

    Guest

    Hello. I am currently working on an RPG like game and I would like my character to have a mana bar. I would like it so whenever my character casts a spell the mana bar goes down and when it hits 0 he can no longer cast any spells. I think the script would have a default mana value and subtract a certain number from that value whenever my character casts a spell. I also have to make sure that the player cannot cast spells once it hits 0 and have it displayed on the HUD. What would be the best way to go about doing this? Thanks a million!
     
  2. QuinnWinters

    QuinnWinters

    Joined:
    Dec 31, 2013
    Posts:
    490
    If you do a search for "unity3d energy bar" or "unity3d health bar" you'll find a ton of tutorials on how to do it. Here's one of the first ones that pulled up for me: http://www.thegamecontriver.com/2014/08/unity-46-create-health-bar-hud.html

    Of course you'll need to add you're own code to stop spells from being cast once the bar is at 0, but that can be done with a simple if statement, such as:

    Code (JavaScript):
    1. if (healthbar == 0) {
    2.     //do something here to keep spells from being cast, such as setting a boolean to false
    3. }
     
  3. Oleygen

    Oleygen

    Joined:
    Feb 21, 2015
    Posts:
    24
    In addition to post above: make separate class smt like HeroStatController with private fields mana and health. Add public boolean methods IsManaEmpty and IsHealthEmpty
     
  4. taralees

    taralees

    Joined:
    Aug 29, 2014
    Posts:
    41
    Awesome
    I am using ootii
    So the big Question is How do you connect it to your Character so every time you cast a spell you lose Mana
    I know how to make a UI and play the Mana bar in the scene but for the Life of me I don't know how to connect it to
    my Character

    HELPP !!!!!
    Thanks