44 lines
1.0 KiB
C#
44 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class TimeController : MonoBehaviour
|
|
{
|
|
public Text timeCounter;
|
|
private float startTime;
|
|
private bool finishedGame;
|
|
|
|
void Start()
|
|
{
|
|
startTime = Time.time;
|
|
timeCounter.color = Color.white;
|
|
finishedGame = false;
|
|
timeCounter.text = "00.00.00";
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (finishedGame)
|
|
return;
|
|
float time = Time.time - startTime;
|
|
float minutesValue = ((int)time / 60);
|
|
string minutes = minutesValue < 10 ? $"0{minutesValue}" : minutesValue.ToString();
|
|
float secondsValue = (time % 60);
|
|
string seconds = (secondsValue < 10) ? $"0{secondsValue.ToString("f2")}" : secondsValue.ToString("f2");
|
|
timeCounter.text = $"{minutes}.{seconds}";
|
|
}
|
|
|
|
public string GetTime()
|
|
{
|
|
return timeCounter.text;
|
|
}
|
|
|
|
|
|
public void Finish()
|
|
{
|
|
finishedGame = true;
|
|
timeCounter.color = Color.yellow;
|
|
}
|
|
}
|