• 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 /
This question was closed Feb 15, 2015 at 10:53 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Digital-Phantom · Feb 15, 2015 at 04:59 AM · stringguitextfontnumbersspacing

How can I add a space between the numbers/digits on my score? (Solved)

Due to the Font type and style I'm using in my game anything written on my GUI has to be spaced apart. (ie SOLVED has to be written as S O L V E D) this was fine until I noticed my score numbers were getting written as normal.

 void Update ()
     {
         // Set the displayed text to be the word "Score" followed by the score value.
         text.text = "S c o r e : " + score;
     }

Is there anyway to separate the numbers on my score once it reached double figures.

???

Comment
Add comment · Show 4
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 incorrect · Feb 15, 2015 at 06:03 AM 0
Share

Sure! $$anonymous$$ake a generic method that will convert anything to string and add spaces. That's too easy.

avatar image Digital-Phantom · Feb 15, 2015 at 06:29 AM 0
Share

'Easy' is such a relative term. Anything is easy 'if' you know how to do it, not so easy if you don't.

avatar image incorrect · Feb 15, 2015 at 08:27 AM 0
Share

Are you kidding?

 string str = "something";
 
 for(int i = 0; i < str.Length-1; i++)
     str = str.Insert(1 + 2i, " ");

Am I genius or is it really simple?

avatar image incorrect · Feb 15, 2015 at 08:29 AM 1
Share

I really need to sleep, but if you want me to, I can help you later to make a bit more versatile solution for you. :)

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by tanoshimi · Feb 15, 2015 at 08:31 AM

I'd use LINQ.

 using UnityEngine;
 using System.Collections;
 using System.Linq; // ADD THIS LINE
 
 public class Whatever: MonoBehaviour {
 
     // Use this for initialization
     void Start () {
 
         int score = 4325;

         string scoreAsStringWithSpaces = score.ToString().Aggregate(string.Empty, (c, i) => c + i + ' ');
 
         Debug.Log (scoreAsStringWithSpaces); // Outputs 4 3 2 5
     }
 }

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 Digital-Phantom · Feb 15, 2015 at 09:20 AM 0
Share

its still not separating the numbers?

alt text

the whole script (as I've probably done something wrong)-

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.Linq; // ADD THIS LINE
 
 public class Score$$anonymous$$anager2 : $$anonymous$$onoBehaviour
 {
     public static int score;        // The player's score.
     
     Text text;                      // Reference to the Text component.
     
     
     void Awake()
     {
         // Set up the reference.
         text = GetComponent <Text> ();
         
         // Reset the score.
         score = 0;
     }
 
 
     // Use this for initialization
     void Start()
     {    
         int score = 4325;
         
         string scoreAsStringWithSpaces = score.ToString().Aggregate(string.Empty, (c, i) => c + i + ' ');
         
         Debug.Log (scoreAsStringWithSpaces); // Outputs 4 3 2 5
     }
 
 
     
     
     void Update()
     {
         // Set the displayed text to be the word "Score" followed by the score value.
         text.text = "S c o r e : " + score;
     }
 }
 

???

score.png (13.8 kB)
avatar image incorrect · Feb 15, 2015 at 10:14 AM 1
Share

Are you kidding?!

  void Update()
      {
          // Set the displayed text to be the word "Score" followed by the score value.
          text.text = "S c o r e : " + score.ToString().Aggregate(string.Empty, (c, i) => c + i + ' ');
      }
avatar image Digital-Phantom · Feb 15, 2015 at 10:33 AM 0
Share

The issue is solved now thanks to yourself and @Tanoshimi. Thanks to both you guys, I really do appreciate the help !

:)

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

How do I find font by passing a string? 1 Answer

Converting 1s and 0s to float 1 Answer

LaTeX Equations or Custom Fonts in Unity GUI and onGUI elements 1 Answer

Controlling font size for iOS application 0 Answers

Canvas Text gets garbled 0 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