System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timer : MonoBehaviour
{
public static float timeMax = StartTime;
public bool timerIsRunning = false;
public Text timeText;
public Dropdown DropdownTimer;
public bool pick = false;
public static float StartTime;
private float PickTime;
public bool check = false;
public void Start()
{
// Starts the timer automatically
timerIsRunning = true;
}
public void Play()
{
if (check == false)
{
StartTime = 60;
}
else
{
StartTime = PickTime;
}
}
public void Drop()
{
switch (DropdownTimer.value)
{
default:
PickTime = 60;
check = true;
break;
case 1:
PickTime = 30;
check = true;
break;
case 2:
PickTime = 45;
check = true;
break;
case 3:
PickTime = 60;
check = true;
break;
}
}
public void Update()
{
timeText.text = ("Time: " + PickTime.ToString());
if (timeMax == 0)
{
timeMax = PickTime;
}
if (timerIsRunning)
{
if (timeMax > 0)
{
timeMax -= Time.deltaTime;
DisplayTime(timeMax);
}
else
{
Debug.Log("Time has run out!");
timeMax = 0;
timerIsRunning = false;
}
}
}
void DisplayTime(float timeToDisplay)
{
timeToDisplay += 1;
float minutes = Mathf.FloorToInt(timeToDisplay / 60);
float seconds = Mathf.FloorToInt(timeToDisplay % 60);
timeText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
}
}