1
Fork 0
mirror of https://github.com/Steffo99/better-tee.git synced 2024-11-26 00:34:18 +00:00
better-tee/Assets/Drawing/Scripts/Timer.cs

43 lines
987 B
C#
Raw Normal View History

2019-09-11 13:13:31 +00:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timer : MonoBehaviour
{
public float startingTime = 0f;
public float time = 0f;
public bool isTriggered = false;
public bool isRunning = false;
protected void Update() {
if(time >= 0f) {
if(isRunning) {
time -= Time.deltaTime;
}
}
else {
time = 0f;
if(isTriggered) {
OnTimeOut(EventArgs.Empty);
isTriggered = false;
}
}
}
public void StartTimer(float startingTime) {
isTriggered = true;
isRunning = true;
this.startingTime = startingTime;
time = startingTime;
}
public event EventHandler TimeOut;
protected virtual void OnTimeOut(EventArgs e)
{
EventHandler handler = TimeOut;
handler?.Invoke(this, e);
}
}