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');
일본어로 올리랴 한국어로 올리랴 힘드네요 ㅎㅎ
조금 유연한 코딩을 할 수 있을것 같네요.
int ScoreLen = 9; // 전체 자리 수
this.Score.GetComponent().text = score.PadLeft(ScoreLen, '0');
|
|
|
|
|
|
|
string.format( "{0:0000000000}", score );
전 요런 코드로 사용했습니다.
PadLeft란 게 있었군요.
|
|
|
|
|
|
|
그냥 score.ToString("D9") 이렇게 하시면 됩니다.
|
|
출처 : http://unitystudy.net/bbs/board.php?bo_table=tip&wr_id=71