-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.cs
More file actions
42 lines (36 loc) · 952 Bytes
/
timer.cs
File metadata and controls
42 lines (36 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Timer : MonoBehaviour
{
[SerializeField] private TMP_Text text;
[SerializeField] private float time;
[SerializeField] private float curTime;
int minute;
int second;
private void Awake()
{
time = 70;
StartCoroutine(StartTimer());
}
IEnumerator StartTimer()
{
curTime = time;
while(curTime > 0)
{
curTime -= Time.deltaTime;
minute = (int)curTime / 60;
second = (int)curTime % 60;
text.text = minute.ToString("00") + ":" + second.ToString("00");
yield return null;
if(curTime <= 0)
{
Debug.Log("시간 종료");
curTime = 0;
yield break;
}
}
}
}