[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초가 됐을 때 실행할 부분
}
}
}
'Unity' 카테고리의 다른 글
[DeVlog] Unity로 Auto Chess 개발하기 1.서버+DB 연동, 로그인/회원가입 시스템 (0) | 2020.10.19 |
---|---|
[Unity/Server] 유니티 간단한 무료 게임 서버 추천 (0) | 2020.10.19 |
[Unity] static 클래스를 통한 상수 관리 (1) | 2020.10.19 |
[Unity/Event] 변수 변경시 정해진 이벤트 호출하기 (0) | 2020.10.19 |
[Unity] Generic DontDestroyOnLoad (0) | 2020.10.05 |