- Home /
How do I make a custom health bar?
Hi, i'm making a project with unity and I need a way to add a custom health bar to my game. When I say "custom health bar", I mean one with textures I have made myself changing every time my player takes damage. I do not wish to have a "box" for my health bar, I would like to use my own custom graphics for my health bar. Thanks!
a search engine is your friend .... http://lmgtfy.com/?q=unity+health+bar
check the answer by cody.burleson here : http://answers.unity3d.com/questions/237381/to-draw-a-health-bar.html
Unity Answers is a $$anonymous$$nowledge Base, so chances are someone has already asked this question, and someone else has answered it well. Please search the title to your question before submitting a new one, thanks.
I understand, but I am having issues using my own graphics, I have already tried searching that several times, and have seen this question. I am trying to make it switch between images I've made when my player gets hurt, will the answer in there complete that?
I see, most just use 2 images, foreground and background. It is absolutely possible to use multiple textures based on the current health. For example, if you are looking at : http://mastergamecraft.com/2012/10/13/create-a-playerhealth-status-indicator-for-unity-gui-part-1/
then it would be a matter of having an if-else cluster or a switch-case to change the foregroundTexture to one of your custom textures, eg :
if ( health < 25 )
{
foregroundTexture = myTexture1;
}
else if ( health < 50 )
{
foregroundTexture = myTexture2;
}
else if ( health < 75 )
{
foregroundTexture = myTexture3;
}
else if ( health < 100 )
{
foregroundTexture = myTexture4;
}
This looks good, thanks! And by the way, why didn't you post this as an answer?
I consider myself lesss skilled to alot of people on this 'site, and if the question appears unanswered then maybe one of them will give a better answer (especially as this is a very fresh question). I just try and help out with the moderation que and answering the new user questions. Sometimes I find the other mods have converted my comments to answers! Anyway, hope this helps, and if this method works I shall convert to answer. Good Luck and Happy Coding =]
sorry for the google thing, there have been alot of questions lately that have been asked numerous times, but as you pointed out and I recognize they usually only deal with 2 textures.
Your answer
Follow this Question
Related Questions
The Game Over creating with audio? 1 Answer
GuiTexture above 3D objects 1 Answer
Issue with GUITexture width. 1 Answer
dragable GUI 0 Answers
How to make a camera's background be another camera's veiw 1 Answer