-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTimerScript.cs
More file actions
31 lines (28 loc) · 891 Bytes
/
TimerScript.cs
File metadata and controls
31 lines (28 loc) · 891 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.Events;
public class NewEmptyCSharpScript : MonoBehaviour
{
public TMP_Text displayTimeText;
private static float currentTime = 300;
private float displayTime;
public UnityEvent gameOverEvent;
void Update(){
currentTime -= Time.deltaTime;
displayTime = Mathf.Round(currentTime);
if(((int)(displayTime/60)) > 1){
displayTimeText.text = ((int)(displayTime/60)).ToString() + "min " +
(displayTime%60).ToString() + "s";
}
else{
displayTimeText.text = displayTime.ToString() + "s";
}
if(currentTime <= 0){
Time.timeScale = 0;
gameOverEvent.Invoke();
displayTimeText.text = "GAME OVER";
}
}
}