using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ScoreText : MonoBehaviour
{
const int DigitMax = 7;
GameObject playerObj;
Player player;
TextMeshProUGUI tMesh;
int number = 0;
int number_old = 0;
// Start is called before the first frame update
void Start()
{
tMesh = this.GetComponent<TextMeshProUGUI>();
playerObj = GameObject.FindGameObjectWithTag("Player");
player = playerObj.GetComponent<Player>();
number = player.playerScore;
number_old = number;
tMesh.text = ZeroFill(number.ToString());
}
void Update()
{
number = player.playerScore;
if( number != number_old)
{
tMesh.text = ZeroFill(number.ToString());
}
number_old = number;
}
string ZeroFill(string _text)
{
string str = _text;
int len = _text.Length;
for( int i = 0; i <( DigitMax - len) ; i++ )
{
str = "0" + str;
}
return str;
}
}