Example script:
var healthGUI : GUIText;
var health = 100.0;
function LateUpdate(){
healthGUI.text = health.ToString();
}
Now when i press play it shows ‘‘100’’, but what do i have to do for it to show ‘‘Health = 100%’’ ?
Example script:
var healthGUI : GUIText;
var health = 100.0;
function LateUpdate(){
healthGUI.text = health.ToString();
}
Now when i press play it shows ‘‘100’’, but what do i have to do for it to show ‘‘Health = 100%’’ ?
hello,
when you play it the line
healthGUI.text = health.ToString();
delete all the text in your guitext and write this number. so you must add Health = in your script
see
healthGUI.text = "Health ="+health.ToString()+"%";
You can leave out .ToString() if you’re concatenating the variable into a string anyway.
healthGUI.text = "Health = " + health + "%";
–Eric
Thank you SOOO much, i wish i could hug you through the screen but i cant.
But i still have a problem i cant solve. So in the variable i type that health is 100.0 but when i get hurt it doesn’t show (example) 91.2 but 91.25168
How can i get it to show 91.2 ?
If your using java script check this out
http://www.javascriptkit.com/javatutors/round.shtml
if c#
http://stackoverflow.com/questions/257005/how-do-you-round-a-number-to-two-decimal-places-in-c
If you want to display the float with single precision, then you want to use String.Format().
healthGUI.text = Health.Format("{0:0.#}", health) + "%";
That should give you a single precision float.