GUI Text showing Player Health

Im a nood scripter and im using the CharacterDamage script and trying to write a script for a GUI Text to make the hitPoints var visible to the player.

function Update

() {var PlayerHealthDisplay : int;

CharacterDamage.hitPoints = PlayerHealthDisplay;

guiText.text = PlayerHealthDisplay;
}

this is the script im using for my GUI text and you can get the CharacterDamage script from the FPS tutorial package

well, I may be wrong, but you don’t want to create variables inside the Update function right? because then they can get created every frame and can just become a real mess.

also, you haven’t actually set PlayerHealthDisplay to anything. You have defined it as an integer but as for now it doesn’t equal anything, it’s just a blank variable (tho I think it’d have a value of 0? idk).

also, you need to define what object has the guiText on it. is it the object that has this script attached? if so, you want to use gameObject.guiText.text = PlayerHealthDisplay;

here’s an example I think -might- work (note I’m a bit of a nub scripter too, so there’s a good possibility this isn’t what you’re wanting, lol).

var PlayerHealthDisplay : int = 10;

function Update(){

CharacterDamage.hitPoints = PlayerHealthDisplay;

gameObject.guiText.text = PlayerHealthDisplay;

}

try that out. I setPlayerHealthDisplay’s value to 10 to start with but you can change it to w/e you like.

cannot convert int to string is what i get now

function Update

() {var PlayerHealthDisplay : int;

CharacterDamage.hitPoints = PlayerHealthDisplay;

guiText.text = ""+PlayerHealthDisplay;
}

Concatenate your int with a string then… Simple enough. You could probably do .toString() as well.