Author Topic: make a health bar  (Read 6972 times)

chanemougasravi

  • Guest
make a health bar
« on: June 12, 2013, 10:10:43 AM »
Hello,
where can i find a tutorial that explain me how to do a energy bar with the progress bar form A to Z:for example if an ennemy shoot the player the energy must down.Until now I didn't find a clear answer.I 'd like to know how to make on relation the bullet script and the energy bar.Thanks a lot

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: make a health bar
« Reply #1 on: June 12, 2013, 01:22:52 PM »
http://www.tasharen.com/forum/index.php?topic=130.0

...it's a sticky post here in the forum...

darkeccho

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: make a health bar
« Reply #2 on: August 05, 2015, 06:27:35 PM »
The video does not show you how to make a health bar, it only shows how to display pop up text, which was already covered in another video. The real question is, how do you convert the damage over to the slider? Using property binding it can only be achieved if the property is a float, which means any int you use must be converted to a float and the declared equal to the integer desired. This is the real health bar making process :)

Hope that helps anyone else.
« Last Edit: August 05, 2015, 06:49:05 PM by darkeccho »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: make a health bar
« Reply #3 on: August 08, 2015, 11:18:00 PM »
The video does not show you how to make a health bar, it only shows how to display pop up text, which was already covered in another video. The real question is, how do you convert the damage over to the slider? Using property binding it can only be achieved if the property is a float, which means any int you use must be converted to a float and the declared equal to the integer desired. This is the real health bar making process :)

Hope that helps anyone else.
Actually it does show you how to make a health bar. Second half of the video adds a visible health bar.

Property bindings are for values of the same type. I am not sure why you are using an integer, but for that you need to set the health bar's value yourself, not use key bindings. Logical value for health is 0-1, 0 meaning 0% health, and 1 meaning 100%. 0.5 is then 50% health. Integer? That doesn't make sense.

darkeccho

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: make a health bar
« Reply #4 on: August 16, 2015, 06:29:29 PM »
Actually no, the second half of the video does not show you that, it displays a bar but you don't show how to link the health with the bar and have it update. The bar did not update in the video alongside you decreasing or increasing the health with clicks.

I was not having any issues using integers, it worked fine for me, only when I linked it to NGUI did I need to convert them to a float in order to use them alongside NGUI.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: make a health bar
« Reply #5 on: August 18, 2015, 04:44:23 PM »
Linking the health to the visible health bar is done via code. For example in Windward each unit creates its own HUD element by instantiating an existing prefab. The reference to this prefab is kept with each unit, so when the unit dies, the instance is destroyed as well. When I need to set a visible health bar, I do this:
  1. unit.hud.healthBar.value = unit.health;
So if your value is an integer, for example 5 lives in total, you'd do this:
  1. unit.hud.healthBar.value = unit.health / 5f;