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 Mike Ledwards · Dec 14, 2010 at 04:38 AM · guitexthealth

How do you get a GUI text to display a var like health?

How do you get a GUI text to display a var like health?

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
2
Best Answer

Answer by Justin Warner · Dec 14, 2010 at 05:13 AM

var currentHealth = 100; var maxHealth = 100; var healthPercent = 100; var damageTaken;

function Update() { healthPercent = healthUpdate()/maxHealth; //Add if statements for the GUI Textures to appear on screen...

} function healthUpdate(damageTaken) { //Do the broadcast message to this function. currentHealth = currentHealth-damageTaken; return currentHealth; }

Read up on broadcast message here: http://unity3d.com/support/documentation/ScriptReference/GameObject.BroadcastMessage.html

Did this off top of my head, some might be wrong, I think it's good though...

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
avatar image
1
Best Answer

Answer by _Petroz · Dec 14, 2010 at 10:38 AM

You can display text on screen using GUI.Label

http://unity3d.com/support/documentation/ScriptReference/GUI.Label.html

Javascript:

function OnGUI () {
    GUI.Label (Rect (10, 10, 100, 20), "Hello World!");
}
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
avatar image
1
Best Answer

Answer by doomprodigy · Dec 14, 2010 at 12:59 PM

public float health = 100f;

void Update () { if (health <= 0) { removePlayer(); } else if (health <= 99) { print("health is now: "+health); GameObject.Find("g_Health").guiText.text = ""+health; }

That works as it is similar to one that I use in one of my games I half finished. everytime your health is deducted by a monster/ enemy void update checks to see if it is below 99 and if it is it renders the new number of HP you have. If your health <= 0 it calls removePlayer () which controlls dying.

Peace,

Comment
Add comment · Show 5 · 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 Mickydtron · Dec 14, 2010 at 02:52 PM 0
Share

Actually, your last piece of code says if health is over 100, add another hundred to it. This will quickly result in it being over 9000.

avatar image doomprodigy · Dec 14, 2010 at 03:42 PM 0
Share

Yeah I know, I just realised and was on my way to edit it. Looks like you beat me to it.

avatar image doomprodigy · Dec 14, 2010 at 03:45 PM 0
Share

Ahh nooo!!! Just realised the DBZ in there T_T

avatar image ina · Dec 14, 2010 at 10:17 PM 0
Share

n00b q - what's DBZ? o.O

avatar image doomprodigy · Dec 15, 2010 at 01:10 AM 0
Share

http://dragonball.wikia.com/wiki/It%27s_Over_9000!

Its a phenomena that got started when the english translator screwed up for Dragon Ball Z. Some guy on youtube made a video and it became a phenomena. Whenever someone says it, it's annoying because it is completely pointless.

avatar image
0

Answer by ina · Dec 14, 2010 at 11:03 AM

1) Expose the variable public var health:int in the script tracking health - call it GameLogic.js
2) Create a GUIText - GUI.Label, etc.. Put a script HealthDisplay in it, but use an exposed public variable named txt for your string
3) In the Update() event of GameLogic, put something like this: GetComponent(HealthDisplay).txt = health;

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

1 Person is following this question.

avatar image

Related Questions

How to display health on screen as text? 1 Answer

Text appear on screen when I stand over object. 1 Answer

How can I add "..." to GUI.Label if it goes past its bounds? 1 Answer

Checking 2 string variables 0 Answers

How to make text that scrolls horizontally? 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