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

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!