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 22, 2011 at 01:19 AM · guihealth

problem with displaying GUI

So I have a 3Dtext object that displays the health of my character. The objects code is as follows

//var PlayerHealthDisplay : float;

//function Update() { //FPSWalker.PlayerHealth = PlayerHealthDisplay; //GetComponent(TextMesh).text = PlayerHealthDisplay.ToString();

//} (ignore the "//", i was using them to see if my script was working.)

But as you know, my static var PlayerHealth, which this script receives its data from, will change through gameplay from receiving damage.

Now this is the issue: My Health will not update. I set a PRINT line of code in FPSWalker to update me when the health is changed. I found : 1. When my 3D text object is disabled, PlayerHealth works, and when disabled, it doesnt work. 2. Placing PlayerHealth as a static var, float var, and int var all allowed PlayerHealth to still work, but when referenced by the script, it does not work. 3. Player Health is set to start at 100, when the 3D object is activated, it stays at 0, but when deactivated, it starts properly at 100. 4. When the 3D text script is active, it makes the PlayerHealth script in FPsWalker stop working also.

Anyone have any clues as to why PlayerHealth is not transferred to the 3DText Object properly?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Jan 22, 2011 at 04:48 AM

:D I think you have to swap this line:

FPSWalker.PlayerHealth = PlayerHealthDisplay;

It should look like:

PlayerHealthDisplay = FPSWalker.PlayerHealth;

otherwise you set your static PlayerHealth var to the value stored in this script and this value is 0 at the beginning.

edit

You don't even need your local var (PlayerHealthDisplay). You could use your static var directly:

GetComponent(TextMesh).text = FPSWalker.PlayerHealth.ToString();

and maybe you want to format the number a bit nicer:

GetComponent(TextMesh).text = FPSWalker.PlayerHealth.ToString("000.0");

that would create a string that always have 3 digits before and 1 digit after. Or use "000" without fractional part.

012.0
005.3
...
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 Padges · Jan 22, 2011 at 09:35 PM 0
Share

:D thanks somuch, what a silly mistake

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

No one has followed this question yet.

Related Questions

Setting Scroll View Width GUILayout 1 Answer

how to display the damage value from a mob 1 Answer

Restart with GUIText 2 Answers

health system problems 0 Answers

Health Bar Only For Falling Damage 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