Source Code for Countdown.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Countdown : MonoBehaviour {
public float timeStart = 60;
public Text textBox;
// Use this for initialization
void Start () {
textBox.text = timeStart.ToString();
}
// Update is called once per frame
void Update () {
timeStart -= Time.deltaTime;
textBox.text = Mathf.Round(timeStart).ToString();
}
}
Source Code for StopWatch.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class StopWatch : MonoBehaviour {
public float timeStart;
public Text textBox;
public Text startBtnText;
bool timerActive = false;
// Use this for initialization
void Start () {
textBox.text = timeStart.ToString("F2");
}
// Update is called once per frame
void Update () {
if(timerActive){
timeStart += Time.deltaTime;
textBox.text = timeStart.ToString("F2");
}
}
public void timerButton(){
timerActive = !timerActive;
startBtnText.text = timerActive ? "Pause" : "Start";
}
}