- Home /
Number 0 not showing up in GUI.Button
Hello, Im trying to make a timer for my game and I need the number 0 to show in front of some numbers. For example :
02:01:01.
I did all the scripting and the timer works fine apart from the number 0 not showing up in front of the other numbers. For example, number 2 appears like 2 only ,not 02.
Is there any way to make it so it appears as 02 ? I tried to switch between float and int but it's still the same.
Thank you.
Answer by Bunny83 · Aug 10, 2014 at 04:48 PM
// C# / UnityScript
var yourTimeString = "" + h.ToString("00") + ":" + m.ToString("00") + ":" + s.ToString("00")
Answer by robertbu · Aug 10, 2014 at 04:51 PM
You can to use string formatting of some sort: ToString() with a format specified, or String.Format(). Example:
#pragma strict
private var i : int = 4;
function Start() {
Debug.Log(i.ToString("D2"));
Debug.Log(String.Format("{0,2:D2}:{1,2:D2}:{2,2:D2}", 2, 4, 8));
}
http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx
Thank you ,the answer above already solved my problem, upvoted tho!
Your answer
Follow this Question
Related Questions
changing GUI Button text with a string array 2 Answers
How do I set a GUI button's text using a string from another script? 0 Answers
Create GUI based on an array 2 Answers
Make String Update for Value (GUI) 1 Answer
Problems with simple dialogue 0 Answers