Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Padges · Jan 20, 2011 at 04:32 PM · guihudhealth

How to make a GUI or HUD

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Thom Denick · Jan 20, 2011 at 04:52 PM

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:

GUIText myText;
int myHeath = 100;
myText.text = myHealth.ToString();
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Padges · Jan 20, 2011 at 05:01 PM 0
Share

:( im not too good at c#, if my variable is PlayerHealth, would i just replace myHealth in your sample script?

avatar image Thom Denick · Jan 20, 2011 at 05:32 PM 0
Share

I think in JS, you don't need the .ToString()... Just: myText.text = myHealth;

avatar image
1

Answer by GamezAtWork · Jan 20, 2011 at 05:22 PM

Actually... Can't you just do a OnGUI script?

Like...

function OnGUI(){
    GUI.Label(0,0,200,200,PlayerHealth);
}

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

theGuiText.text = PlayerHealth.ToString();

As he has done so above, with theGUiText referring to the GUIText you created, and PlayerHealth being the float/int variable you created.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image user-4565 (google) · Jan 20, 2011 at 05:29 PM 0
Share

i cant do a label, because the unity engine gives me error "No appropriate version of blah blah bah for the argument list

avatar image
1

Answer by user-4565 (google) · Jan 20, 2011 at 05:56 PM

ok so, this is my new code

var PlayerHealthDisplay : int;

FPSWalker.PlayerHealth = PlayerHealthDisplay;

guiText.text = PlayerHealthDisplay;

but the console says "Cannot convert integer into String".

Now what?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Thom Denick · Jan 20, 2011 at 05:59 PM 0
Share

Yeah sorry about that, I guess you do need to do to convert PlayerHealthDisplay into a string.

Just try: guiText.text = PlayerHealthDisplay.ToString();

avatar image user-4565 (google) · Jan 20, 2011 at 06:07 PM 0
Share

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

avatar image
0

Answer by Unity user · Jan 28, 2011 at 01:15 AM

If you want it Updated you should keep it inside of a function Update(){}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Where can I find the scripts used in the Player State Machine & HUD/GUI Tutorials? 1 Answer

How to display health on screen as text? 1 Answer

Can't get Gui Pos on top of Enemy ingame! 0 Answers

GUI appears even when placed behind an object. 1 Answer

OnMouseOver Tower Gui Health Bar 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges