LoginSignup
3
2

More than 5 years have passed since last update.

【Unity】【NGUI】UILabelにゼロ埋め処理

Last updated at Posted at 2013-07-06

1.png

Source Code

// UILabelのゲームオブジェクト
public GameObject Score;

// 既にUILabelのTextに9桁の0と1を入力した数字を取得(最初は000000001)
string score = this.Score.GetComponent().text;

// 前回のスコアをInt型に変換し、+1にする
int totalScore = System.Convert.ToInt32(score) + 1;

// 数字を文字列型に変換
score = totalScore.ToString();

// 最後に数字以外は0を埋める
this.Score.GetComponent().text = score.PadLeft(9, '0');

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2