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;
|
2019-09-11 13:51:05 +00:00
|
|
|
|
|
|
|
private bool isTriggered = false;
|
|
|
|
private bool isRunning = false;
|
2019-09-11 13:13:31 +00:00
|
|
|
|
|
|
|
protected void Update() {
|
|
|
|
if(time >= 0f) {
|
|
|
|
if(isRunning) {
|
|
|
|
time -= Time.deltaTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(isTriggered) {
|
2019-09-12 15:37:20 +00:00
|
|
|
OnTimeOut();
|
2019-09-11 13:51:05 +00:00
|
|
|
time = 0f;
|
2019-09-11 13:13:31 +00:00
|
|
|
isTriggered = false;
|
2019-09-11 13:51:05 +00:00
|
|
|
isRunning = false;
|
2019-09-11 13:13:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-11 13:51:05 +00:00
|
|
|
public void TimerSet(float startingTime) {
|
2019-09-11 13:13:31 +00:00
|
|
|
isTriggered = true;
|
2019-09-11 13:51:05 +00:00
|
|
|
isRunning = false;
|
2019-09-11 13:13:31 +00:00
|
|
|
this.startingTime = startingTime;
|
|
|
|
time = startingTime;
|
|
|
|
}
|
|
|
|
|
2019-09-11 13:51:05 +00:00
|
|
|
public void TimerStart() {
|
|
|
|
isRunning = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void TimerPause() {
|
|
|
|
isRunning = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void TimerCancel() {
|
|
|
|
time = 0f;
|
|
|
|
isTriggered = false;
|
|
|
|
isRunning = false;
|
|
|
|
}
|
|
|
|
|
2019-09-12 15:37:20 +00:00
|
|
|
public event Action OnTimeOut;
|
2019-09-11 13:13:31 +00:00
|
|
|
}
|