[SerializeField]
private Text _timerText;
  
private float _timer;
    
    public void StartGame() // 게임 시작 함수
    {
        StartCoroutine(GameScheduler());
    }

    private IEnumerator GameScheduler()
    {
        _timer = 30f;
        isPlaying = true;

        while (_timer > 0 && isPlaying)
        {
            _timer -= Time.deltaTime;
            string minutes = Mathf.Floor(_timer / 60).ToString("00");
            string seconds = (_timer % 60).ToString("00");
            _timerText.text = string.Format("{0}:{1}", minutes, seconds);
            yield return null;

            if (_timer <= 0)
            {
            	// 30초가 다 지나 timer가 0초가 됐을 때 실행할 부분
            }
        }
    }

 

TimeText UI mm:ss 포맷

 

+ Recent posts