- Home /
Question by
z25assassins · Jul 30, 2017 at 07:44 PM ·
timerstringupdate functionformatstring formatting
String format not working
Probably something really simple I am missing. But I can't seem to fix this problem. Do you guys/gals see the problem anywhere?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TimerScript : MonoBehaviour {
public Text theText;
private double time = 0;
private int check = 1;
public void Update(){
if (check == 0) {
time += Time.deltaTime;
theText.text = string.Format("{0:0.0}",time.ToString());
}
}
public void startPressed(){
check = 0;
}
public void stopPressed(){
check = 1;
}
}
screenshot-10.png
(358.0 kB)
Comment
Best Answer
Answer by z25assassins · Jul 30, 2017 at 07:58 PM
Fixed... Changed this
theText.text = string.Format("{0:0.0}",time.ToString());
To
theText.text = time.ToString("0000.00");
Hope can anyone explain why the latter works, but not the former? Thanks