Count Down & Stop Watch Timers

I haven’t found an easy way to create these in Bolt do I made them in C#, they come in handy for many kinds of games.

Count Down Timer

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Bolt;

public class CountDown : MonoBehaviour
{
    public float timeRemaining = 10;
    public bool timerIsRunning = false;
    public Text timeText;

    private void Start()
    {
        // Starts the timer automatically
        timerIsRunning = true;
    }

    void Update()
    {
        if ((bool)Variables.ActiveScene.Get("Timer_Running") == true)
        {
            if (timeRemaining > 0)
            {
                timeRemaining -= Time.deltaTime;
                DisplayTime(timeRemaining);
            }
            else
            {
                Debug.Log("Time has run out!");
                timeRemaining = 0;
                timerIsRunning = false;
                Variables.ActiveScene.Set("Timer_Running", false);
                Variables.ActiveScene.Set("Time_Out", true);
            }
        }
    }

    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);
    }
}

The count down timer starts when the timerIsRunning variable is set to true and displays itself on a UI text called timeText.

Stop Watch Timer

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Bolt;

public class StopWatch : MonoBehaviour
{

    public Text text;
    float theTime;
    public float speed = 1;


    // Use this for initialization
    void Start()
    {
        //text = GetComponent(-INSERT LESS THAN SIGN -)Text(-INSERT GREATER THAN SIGN -)();
    }

    // Update is called once per frame
    void Update()
    {

        if ((bool)Variables.ActiveScene.Get("Timer_Running") == true)
        {
            theTime += Time.deltaTime * speed;
            string hours = Mathf.Floor((theTime % 216000) / 3600).ToString("00");
            string minutes = Mathf.Floor((theTime % 3600) / 60).ToString("00");
            string seconds = (theTime % 60).ToString("00");
            text.text = hours + ":" + minutes + ":" + seconds;
        }
    }

    public void ClickPlay()
    {

        Variables.ActiveScene.Set("Timer_Running", true);
    }

    public void ClickStop()
    {
        Variables.ActiveScene.Set("Timer_Running", false);
    }


}

The Stop Watch timer if the Scene Variable called Timer_Running is true the timer starts going until that same variable is set to false. This code outputs the time to a UI text called “text”… how creative lol.