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 bhavesh123 · Mar 10, 2014 at 01:19 PM · variablestringscoreintgui text

How do i link a GUI text to a variable text which is a integer?

Actually i want to display health in the form of text and i have a variable named Health and i want the the variable's text to be displayed in the GUI, but it has error saying 'cannot convert int to string' what do i do? Here's the code:- #pragma strict

     var MaxHealth = 100;
     var Health : int;
     
     var healthtext : GUIText;
     
     function Start ()
     {
         Health = MaxHealth;
         healthtext.text = Health;
         
     }
     
     //this not the problem so don't read the code below-
     //function ApplyDammage (TheDammage : int){
     //    Health -= TheDammage;
     //    
     //    if(Health <= 0)
     //    {
     //        Dead();
     //    }
     //}
     
     //function Dead()
     //{
     //    RespawnMenuV2.playerIsDead = true;
     //    Debug.Log("Player Died");
     //}
     
     //function RespawnStats ()
     //{
     //    Health = MaxHealth;
     //}
 
Comment
Add comment · Show 6
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 bhavesh123 · Mar 11, 2014 at 08:19 AM 0
Share

Its not working. There are no errors but its not working.

avatar image robertbu · Mar 11, 2014 at 08:22 AM 0
Share

Not working means what? And who is this comment for? Note the 'add new comment' button on the lower right of each question. Note that you code is only executed once. If you want your values to change as Health changes, then you will need to execute it every frame, or at least every time Health changes.

avatar image KiraSensei · Mar 11, 2014 at 10:31 PM 0
Share

Exactly. You just asked us how to correct your error. If you want to make this work during the game, you need to put the healthtext.text = Health.ToString(); line into the Update() method.

Unless you don't specify what your problem is, you won't have a better answer than you already had.

avatar image bhavesh123 · Mar 12, 2014 at 02:51 PM 0
Share

Now its working actually i had put it at two places thanks a lot. No need of update method fisrt i had put it in function start and then in funtion apply damage.

avatar image bhavesh123 · Mar 12, 2014 at 02:52 PM 0
Share

thanks $$anonymous$$iraSensei and ShadoX

Show more comments

2 Replies

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

Answer by KiraSensei · Mar 10, 2014 at 01:38 PM

Use this :

healthtext.text = Health.ToString();

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
0

Answer by ShadoX · Mar 10, 2014 at 01:38 PM

 healthtext.text = Health.toString();

http://www.w3schools.com/jsref/jsref_tostring_number.asp

Hope this helps :)

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

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

string + int = variable 2 Answers

Converting a single String character to representative int. How? Javascript 2 Answers

Check if a guiText = a number? 2 Answers

'Cannot convert int to String' 2 Answers

I can't print a int.ToString() variable in a guiText.text 1 Answer


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