Search Unity

Health Bar - FREE!

Discussion in 'Made With Unity' started by ExDeaDguY, Jul 15, 2010.

  1. ExDeaDguY

    ExDeaDguY

    Joined:
    Aug 25, 2009
    Posts:
    503
    HEY GUYS! Heres another *free* script to learn from! :). Since I see a lot of posts about "wanting a script to do this or that" I'm giving them to you for free! This one is pretty simple all you need to do is attach the script to your player object. Set up the variables and you got yourself a health bar generated from 2d textures!


    Web Player:
    https://dl.dropbox.com/u/6629353/HealthBar.html


    -Source is attached-, Music NOT included!


    Let me know if you like it!


    Be sure to check out these threads:
    Advanced Inventory Equipment System
    Simple Inventory - Free
    Simple Health Bar - Free
     

    Attached Files:

  2. _Slava

    _Slava

    Joined:
    Sep 30, 2009
    Posts:
    97
    Nice script and music, as always :)
     
  3. mikesgames

    mikesgames

    Joined:
    Apr 16, 2010
    Posts:
    1,071
    cool!

    Not a fan of the song though!
     
  4. mrbdrm

    mrbdrm

    Joined:
    Mar 22, 2009
    Posts:
    510
    thank you keep it up :)
     
  5. BrettFromLA

    BrettFromLA

    Joined:
    Jan 29, 2009
    Posts:
    244
    Nice-looking health bar!

    But what's a Juh-Jeela Girl? (I do like the song's beat!)
     
  6. ExDeaDguY

    ExDeaDguY

    Joined:
    Aug 25, 2009
    Posts:
    503
    Lmao! Drug Dealer Girl! ahahahah

    Get it: "When you got some purple", "Light one with me" :p.
     
  7. wafflehead66

    wafflehead66

    Joined:
    Sep 22, 2010
    Posts:
    21
    so how do i make myself die when this is at zero
     
  8. ExDeaDguY

    ExDeaDguY

    Joined:
    Aug 25, 2009
    Posts:
    503


    o_O, Lol really?! That part is up to you ^.^, Depending on how youre game is set up. Create a function that checks your health. have it get checked every time the player is hit.


    ex:

    function DeathCheck(){
    if(health<=0){
    //do some stuff that makes the player die. show an animation. move him to the beginning of the level. or whatever.
    }
    }
     
  9. gooongalooo

    gooongalooo

    Joined:
    May 6, 2010
    Posts:
    140
    if(health<=0){
    Debug.Log("you are dead...but you still can run, because you forgot to add a bloody DIEDIEDIE animation...or a huge explosion... like a super nova...hey...you are still reading..the game is over, dude - YOU LOOOOOOSE!!! :D ");
    }

    ;)
     
  10. ExDeaDguY

    ExDeaDguY

    Joined:
    Aug 25, 2009
    Posts:
    503
    nice 1. lol
     
  11. 3dDude

    3dDude

    Joined:
    Jul 4, 2010
    Posts:
    1,067
    what is the song? lol

    nice script(even tho i know how to do this anyway. good for beginners!)
     
  12. Kyuss77

    Kyuss77

    Joined:
    Jan 20, 2010
    Posts:
    121
    Please release more source code for free. I don't care what. You're notation makes it easy to follow and learn from for us artist who are not so great with programming.
     
  13. gooongalooo

    gooongalooo

    Joined:
    May 6, 2010
    Posts:
    140
    well, here´s the next healthbar
    adds hp if energy is low and so on...

    have fun
     

    Attached Files:

  14. sunbird606

    sunbird606

    Joined:
    Apr 22, 2012
    Posts:
    1
    Nice of all :)
     
  15. omelchor

    omelchor

    Joined:
    Jun 15, 2011
    Posts:
    20
    Thanks!
     
  16. primus88

    primus88

    Joined:
    May 14, 2013
    Posts:
    611
    Hello,

    My question is , can I use this to follow my units by floating over their head ?
    Like the healthbar in RTS games. If so, how can I do it ?

    Thanks
     
  17. MyIsaak

    MyIsaak

    Joined:
    May 23, 2013
    Posts:
    49
    Wow! Thanks for sharing this to the community ExDeaDguY! Btw luv the music :D
     
  18. ExDeaDguY

    ExDeaDguY

    Joined:
    Aug 25, 2009
    Posts:
    503
    No :(. Youll need to use GUI and check if enemy is in view and if so track the enemy from the screen point and display it over his head. but in the screen. Or use a physical object that is parented to the enemy and update that objects renderer (Image on material) with proper image. and so on.
     
  19. stilos

    stilos

    Joined:
    Feb 25, 2015
    Posts:
    2
    For a reason i get an error when i apply the scripts on my Player! i get to see the gui in the center but not the health bar!
    The error is IndexOutOfRangeException: Array index is out of range.
     
  20. ExDeaDguY

    ExDeaDguY

    Joined:
    Aug 25, 2009
    Posts:
    503
    Hey there, This is super old so I have no idea if this still works or not.. But I think the error may be caused from.. One of the scripts has an array on it, after applying it to a gameobject you need to apply texture2ds to some variables.. Should be an array for images of the bar and different values. Ex: 10%, 20%, 30%, 100% etc. element 0 is probably 0%, and the last element would be 100%