- Home /
Health Question
Hello I need help with my health gui I have Everything I need for the Gui, I have it in the right place on the screen but its just Gui text. I was wondering if I could have it so I still keep the Gui text but have it decrease if the Player gets hit. Anything (scripts,Tutorials) would be really helpful. Thank you - ryan 123321
Do you have a health script on your player? Is there an 'HP' (or something) variable that you can query?
Answer by DGArtistsInc · Mar 07, 2012 at 02:32 AM
Yes it is possible. Make an int variable called health and set that to how much health you want. Then make a variable that is an empty gameobject called health text or something. then set your gui text to that variable.(Make sure all of this is in the same script BTW.) Then access the GUI text's text attribute and set it to the health variable. Then whenever your character gets hit subtract damage from your health variable. Heres an example.
var health = 100;
var guiText = gameObject;
function Update()
{
guiText.text = health + "";
}
then make a function that subtracts damage from the health variable when the character is hit! If there are any errors or it is not what you want make sure to comment in reply!
Yeah there's an error. Spell Update properly. Also, why not use health.ToString() ins$$anonymous$$d of relying on automatic type promotion?
$$anonymous$$y bad thanks for small detail improvement
thank you. I tryed making a script and it was simlar to this and it didnt work! Thank you so much.
sorry in the last comment it may have sounded like I was bla$$anonymous$$g you for the failure of the script but the only thing to blame was my lack of javascript skills. I am sorry if it came across that way and that was not the way I meant it. In other words Thank you for making a script and I tryed to create one but sadly it didnt work.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Health and damage reciever 1 Answer
Bullet not destroying on collision 1 Answer
Damage taking? 1 Answer