How to CountDown On Start ?

Hi guys,

i’ve a script which freezes time at start and release time after 3 seconds. But i couldn’t print the countdown in-game text. Can you help me ? Thanks…

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

public class InGameUI : MonoBehaviour
{
    public Text scoreText;
    public Text timerText;
    private float startTime;

    public GameObject goCountDown; //To deactivate UI AFTER 3 SECS...
    public Text countDownText; //UI TO PRINT 3 2  1 0 AND START
    private float timeLeft;

    void Awake()
    {
        goCountDown.SetActive(true);
    }

    void Start()
    {
        scoreText.text = Score.score.ToString();

        StartCoroutine("CountDown");
    }


    void Update()
    {
        //how to print countdown in game text ?

        scoreText.text = Score.score.ToString();

        if (Time.timeScale == 1)
        {

            MyTimer();
        }
    }

    void MyTimer()  //IN-GAME TIMER TO STORE PLAY TIME
    {
        float t = Time.time - startTime;

        string hours = ((int)t / 3600).ToString();
        string minutes = ((int)t / 60).ToString();
        string seconds = (t % 60).ToString("f0");

        timerText.text = hours + "h " + minutes + "m " + seconds + "s";
    }

    IEnumerator CountDown()
    {
        Time.timeScale = 0;

        goCountDown.SetActive(true);

        timeLeft = Time.realtimeSinceStartup + 3f;

        while (Time.realtimeSinceStartup < timeLeft)
            yield return null;

        Time.timeScale = 1;

        goCountDown.SetActive(false);
    }
}

I don’t see any code that displays the time during countdown.

Also, in

if (Time.timeScale == 1)

you are comparing a float to exactly 1f, which is a very bad idea. Either use an Approximation, or use a ‘grater than’ comparison, e.g.

if (Time.timeScale > 0.9f)