Problem with 3 2 1 countdown timer

I’m trying to implement a countdown timer to my game but cannot get it to work. At the moment, I have game instructions presented on Awake. After clicking a start button on the last instruction panel, I want to hide the instructions panel and activate the countdown timer (counts down from 3). Once the countdown timer reaches 0, I want to hide the countdown timer text and start the game through my bool gamePlaying which is set to true. I also have an in-game timer which is being called in Update in a different script, so that when that timer reaches 0, the game will end.

At the moment, my StartGame() method is being called on click of the start button using Canvas UI. Once I click start, the game instructions panel is hidden and the countdown timer is shown but it is stuck on 3 and will not count down. I am not sure what’s going on. Any help is greatly appreciated!

public TextMeshProUGUI countdownText;

public void StartGame()
    {
        startInstruction2.SetActive(false);
        CountDownTimer();
    }

    private void CountDownTimer()
    {
        float countdownTime = 3f;
        countdownText.gameObject.SetActive(true);
        if (countdownTime > 0)
        {
            countdownTime -= 1 * Time.deltaTime;
            countdownText.text = countdownTime.ToString();
        }

        if (countdownTime <= 0)
        {
            countdownText.gameObject.SetActive(false);
            status = GetComponent<GameStatus>();
            status.gamePlaying = true;
            Time.timeScale = 1;
        }
    }

CountDownTimer will only ever enter once from StartGame so your current approach will not work. It will run through that entire function without counting down. You could make CountDownTimer into a coroutine. Use a while loop in the coroutine that keeps going until the game is started. Inside the loop have a yield instruction that waits a second.

Pseduo code.

Coroutine
{
     // set counter for the number of seconds to wait.
    // set text
    while(game isnt started)
    {
        // wait a second
        // update counter
        //  Set text or hide it depending on the counter. Do any logic/activation/deactivation if needed
        // if the counter is at the correct number start the game
    }
}