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 DonGato · May 13, 2011 at 05:15 PM · javascriptguitextint

2 int's displayed in one GUIText.

Okay, I have this

guiText.text = "" +displayMinutes ":" +displaySeconds;

attached to a GUIText object. Unfortunately it doesn't work...

guiText.text = "" +displayMinutes;

works perfectly, as does

guiText.text = ":" +displaySeconds;

I just can't put them together.

Obviously the rest of this script is a timer script, which works correctly. So, what do I do...

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

3 Replies

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

Answer by almo · May 13, 2011 at 05:22 PM

Did you mean

guiText.text = "" + displayMinutes + ":" + displaySeconds;

Though I would recommend

guiText.text = displayMinutes.ToString() + ":" + displaySeconds.ToString();

for clarity.

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 DonGato · May 13, 2011 at 05:27 PM 0
Share

Thank you, that did it. Sorry for such a dumb question, I am new to this...

avatar image DonGato · May 13, 2011 at 05:34 PM 0
Share

Does ToString() mess up the number properties of the variable, or does it not permanently change it to a string?

avatar image almo · May 13, 2011 at 05:47 PM 0
Share

ToString is a function that returns a string containing a representation of the object it is called on. If you search Unity's scripting docs for ToString, you will see a lot of different objects support it. So it won't alter the object you call it on. :)

avatar image yoyo · May 13, 2011 at 06:50 PM 0
Share

"adding" something to a string will automatically ToString-ify it, so putting the .ToString() call is optional, but perhaps makes it more clear what's happening.

avatar image DonGato · May 13, 2011 at 07:20 PM 0
Share

ToString() just makes it more confusing to me, and takes longer to type, so I will carry on with what I am doing. Anyway, thanks for the clarification guys...

avatar image
1

Answer by yoyo · May 13, 2011 at 06:58 PM

Adding strings together with + works fine. Another option though is to use string formatting, like so ...

guiText.text = string.Format("{0}:{1}", displayMinutes, displaySeconds);

Whether you like the syntax better is a matter of taste, but this also gives you much more control over how things are formatted. See the documentation for String.Format for details.

Comment
Add comment · Show 3 · 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 DonGato · May 13, 2011 at 07:21 PM 0
Share

Interesting. Seems more confusing though...

avatar image yoyo · May 13, 2011 at 08:30 PM 0
Share

Like I said, a matter of taste ... :-)

avatar image almo · May 19, 2011 at 09:48 PM 0
Share

I didn't know that one Yoyo. Thanks. :)

avatar image
0

Answer by FLASHDENMARK · May 13, 2011 at 05:33 PM

Every time you want to add something to a guitext then you will need to have +s in between.

When I was first learning I used to memorized by remembering how I write text:

Lets say I want to add several things to a guiText I used to compare it to a grocery list e.g:

My shopping list!

I need: Milk, bread, dogfood, 20 tampons, candy, batteries. And so on. If I wanted to use that in a guiText then i would say:

guiText.text = "" + Milk + dogfood + 20 tampons + candy + ":" + batteries;

If you get my point I just replaced the commas with +s.

I thought I would tell you this because it helped me a lot when I was first learning.

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

No one has followed this question yet.

Related Questions

GUI Text to GUI Label Script? 1 Answer

How do I change the text of a gui image text 1 Answer

Animation depending on the Int value 0 Answers

changing font + size of text 1 Answer

Random int Value 3 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