|
I know there are tons of threads on here about making a gui but none of them seem to be working for me. I am trying to use a GUI.Label and make a "PlayerHealth" variable visible to the player as a number, not a healthbar. i.e. it shows 100 when at max and you get hit it falls down to 94. Is there any way to link a interger variable into a GUI.Label script? thanks in advance
(comments are locked)
|
|
I think what you are looking for is not GUI.Label, but a GUIText http://unity3d.com/support/documentation/ScriptReference/GUIText.html When you have the Text in place, you can simply create a reference to it in your script, and change it's value by changing .text with your script. So in C# just: :( im not too good at c#, if my variable is PlayerHealth, would i just replace myHealth in your sample script?
Jan 20 '11 at 05:01 PM
Padges
I think in JS, you don't need the .ToString()... Just: myText.text = myHealth;
Jan 20 '11 at 05:32 PM
Thom Denick
(comments are locked)
|
|
Actually... Can't you just do a OnGUI script? Like...
On the object that contains PlayerHealth? http://unity3d.com/support/documentation/ScriptReference/GUI.Label.html If you're talking about using a GUIText though, like Smorpheus said above... It would be kinda like
As he has done so above, with theGUiText referring to the GUIText you created, and PlayerHealth being the float/int variable you created. i cant do a label, because the unity engine gives me error "No appropriate version of blah blah bah for the argument list
Jan 20 '11 at 05:29 PM
user-4565 (google)
(comments are locked)
|
|
ok so, this is my new code
FPSWalker.PlayerHealth = PlayerHealthDisplay; guiText.text = PlayerHealthDisplay; but the console says "Cannot convert integer into String". Now what? Yeah sorry about that, I guess you do need to do to convert PlayerHealthDisplay into a string. Just try: guiText.text = PlayerHealthDisplay.ToString();
Jan 20 '11 at 05:59 PM
Thom Denick
ah i got it, it works perfectly :D now i just need to find how to keep the health updated all the time lol thank you guys so much
Jan 20 '11 at 06:07 PM
user-4565 (google)
(comments are locked)
|
|
If you want it Updated you should keep it inside of a function Update(){}
(comments are locked)
|
