Add timer to spelling bee
This commit is contained in:
34
Assets/Scripts/Timer.cs
Normal file
34
Assets/Scripts/Timer.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Timer : MonoBehaviour
|
||||
{
|
||||
private float timerValue;
|
||||
public Text timerText;
|
||||
|
||||
void Start()
|
||||
{
|
||||
timerValue = 0.0f;
|
||||
timerText = GetComponent<Text>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
timerValue -= Time.deltaTime;
|
||||
|
||||
if (timerValue <= 0.0f)
|
||||
{
|
||||
timerValue = 0.0f;
|
||||
// Handle end of timer
|
||||
}
|
||||
|
||||
int minutes = Mathf.FloorToInt(timerValue / 60.0f);
|
||||
int seconds = Mathf.FloorToInt(timerValue % 60.0f);
|
||||
|
||||
timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
|
||||
}
|
||||
|
||||
void addSeconds(int seconds) {
|
||||
timerValue += (float) seconds;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user