- Home /
Gui Text not showing up when I click play...
Well, I have a script for xp and hp systems for my character. The script includes displaying the stats in Gui. The xp gui works, but the hp one doesn't. What happens is that the hp stats pop up for a second after i click play, but then they disappear, and turn into Guitext. Please help me figure this one out. Thanks!:)
The description will help us understanding the code you have not yet provided. :)
Here is the script: var curHealth : int = 100; var maxHealth : int = 100;
var healthtext : GUIText;
function Start () {
healthRegen();
}
function Update () {
healthtext.text = curHealth + " / " + maxHealth;
if(curHealth < 0 ) {
curHealth = 0;
}
if(curHealth > 100) {
curHealth = 100;
}
if(Input.Get$$anonymous$$eyDown("e")) {
curHealth -= 10;
}
}
function healthRegen () {
for(i=1;i>0;i++) {
yield WaitForSeconds(0.5);
if(curHealth < maxHealth) {
curHealth++;
}
}
}
Using the OnGUI() function would be much better in my opinion
Answer by umangindianic · Jun 13, 2013 at 04:38 AM
I think so, you haven't create GUIText object in Hierarchy panel. First create the GUIText object in Hierarchy and assign the same object to script as a GUIText.
Answer by bubzy · Jun 13, 2013 at 11:57 PM
c#
void OnGUI()
{
GUI.Label (new Rect(0,0,100,20),curHealth);
}
js
function OnGUI ()
{
GUI.Label (Rect(0,0,100,20),curHealth);
}