- Home /
Generate Fixed Distance String
Right now I am working on calculating distance that object travel in generating distance I have no problem. It works perfect as expected but to display it on screen become difficult for me.
Basically I want distance displayed as '00013', in this format alway want to prefix '0' for each calculated distance. For this I write this type of code but I know it is poor piece of coding.
if(GameManager.Instance.DistanceTraveled <10)
distanceText.text = "000" + Mathf.Ceil(GameManager.Instance.DistanceTraveled);
else if(GameManager.Instance.DistanceTraveled <100)
distanceText.text = "00" + Mathf.Ceil(GameManager.Instance.DistanceTraveled);
else if(GameManager.Instance.DistanceTraveled <1000)
distanceText.text = "0" + Mathf.Ceil(GameManager.Instance.DistanceTraveled);
I want some great way to display distance string with any type of if ladder. Please give some guidance in this.
Answer by Eric5h5 · Jul 26, 2014 at 03:50 AM
var distance = Mathf.Ceil (GameManager.Instance.DistanceTraveled);
distanceText.text = distance.ToString ("00000");
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Rotate GameObject using Coroutine 2 Answers
Move Object by dragging (mobile) makes the balls fall from the cup 1 Answer
Writing on text file in an Android Build 1 Answer
Dynamic Path Generation for 2D 0 Answers