- Home /
Trying to make a unique type of health 'bar'
Hi, for the game I'm working on, I'd like the health bar to be a bit more unique than the standard UI Sliders. My game has a bunch of different characters with different amounts of health, and what I'm wondering is what the best way to try and make a slider that either:
1) Increases in length the higher the max HP of the character, or 2) Tracks health in 'dots' that disappear as they take damage (Like from the Ur-Quan Masters, link is here: https://www.youtube.com/watch?v=59NFcw54STI )
Any tips would be much appreciated.
Answer by Stratosome · Sep 14, 2018 at 04:55 AM
Hiya!
Well, it seems fairly straight forward to me but perhaps I'm misunderstanding something. I'll look at your first... uh, question (?). So, if you want a slider that increases in length as the character's max health increases, couldn't you just make the length of that bar equal to that max health value or something related? If you've got a little GUI element to represent this slider, just set the width of it depending on the max health. For your second question, if you wanted to potentially have dots represent the max health, couldn't the number of dots just be the max health value? Perhaps you'd draw 10 black dots (max health of 10), and then 9 red dots over the black ones (current health is 9). As the current health drops or increases, just draw or remove the dots. Not quite sure how else to answer your question here... If you have perhaps a bit more specific of a question though, I'd be happy to try to answer it.
For the second question. you could also use a particle system to achieve something like in the video and play with the life span (amount of the dots) and a gradient over life time.. It might look good but wouldn't be as accurate as manually drawing those dots.
I'm sorry, thank you for your help, though I probably worded it badly. When I try to increase the length of the healthbar (which I want in the corner) the bar increases in length on both sides and goes off-screen. Is there a way to fix that? And for the dots thing, is that a Gizmos thing? Sorry, it might be kind of obvious that I'm kinda a noob
Gizmos are more for just debugging things. You'd probably want to use sprites for your health "bar". As for your UI Slider growing on both sides ins$$anonymous$$d of just one, there are a couple ways you could fix this. 1. You could adjust the x position while changing the width of the slider. This way one side of it would appear to be still. 2. Alternatively, the EASIER WAY, would be to find the Slider component on your UI object, and change the pivot to something else. By default, it is X = 0.5, Y = 0.5. If you make the X value 0.0, the left side of your slider won't move while growing/shrinking.
Thank you very much, the pivot worked perfectly. As for using sprites for the dot-based bar, considering max health values can reach about 40 but I still want 1 dot to equal 1 HP, it would be possible, just be very tedious to do it. This has been very, very useful. Thank you.
Your answer
Follow this Question
Related Questions
Player health dropping far to fast 1 Answer
I need help with the player's health points 1 Answer
Health Bar decreases in both directions 0 Answers
How to make my health decrease? 1 Answer