-
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) · 771 Bytes
/
Timer.cs
File metadata and controls
42 lines (36 loc) · 771 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;
public class Timer : MonoBehaviour {
// Use this for initialization
Text txt;
public GameObject player;
void Start () {
txt = this.GetComponent<Text>();
timeLeft = rewindTime;
}
public float rewindTime = 8.0f;
float timeLeft;
bool isRunning = true;
void RestartTime()
{
timeLeft = rewindTime;
txt.color = Color.black;
isRunning = true;
}
void Update()
{
if (isRunning) {
timeLeft -= Time.deltaTime;
txt.text = timeLeft.ToString ("0.00");
if (timeLeft < 0) {
timeLeft = 0;
txt.text = timeLeft.ToString ("0.00");
txt.color = Color.red;
isRunning = false;
player.SendMessage ("StartRewind");
}
}
}
}