-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimer.cs
executable file
·43 lines (37 loc) · 996 Bytes
/
Timer.cs
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
43
using UnityEngine;
using System.Collections;
namespace UberTools
{
public class Timer
{
//Starts a timer
public void Start(float duration)
{
StartTime = Time.time;
Duration = duration;
}
//Returns a value from 0.0 to 1.0
public float GetCompletionAmount()
{
if (Duration <= 0.0f)
return 0.0f;
float runningTime = Time.time - StartTime;
var amount = runningTime / Duration;
if (amount >= 1.0f)
{
return 1.0f;
}
return amount;
}
//Returns whether or not the timer has elapsed
public bool Finished
{
get
{
return StartTime < 0 || Time.time - StartTime > Duration;
}
}
private float StartTime = -1.0f;
private float Duration = 0;
}
}