How to stop whole game and do some text changes on 3D text?

Hi I am writing my Pong game and there is a 3D text “Start Game”, once player click on it I want to stop the whole game and run “text animation”:
Get ready in 5…
Get ready in 4…
Get ready in 3…
.
.
.

Now in my javascript I wrote this:

function wait(n: float) {
	//wait for n seconds
	var t1: float;
	
	t1 = Time.time;
	while ((Time.time - t1) < n ) {
		//waiting
	}
}

And in the event:

function OnMouseOver () {
		
		if(Input.GetMouseButton(0)) {    			
			//stop the game
			Time.timeScale = 0;
			    			
			//play GET REDY animation before start
			GetComponent(TextMesh).text = "Get ready in 5....";
			wait(1);
			GetComponent(TextMesh).text = "Get ready in 4....";
			wait(1);
                    GetComponent(TextMesh).text = "Get ready in 3....";
			wait(1);
                    GetComponent(TextMesh).text = "Get ready in 2....";
			wait(1);
                    GetComponent(TextMesh).text = "Get ready in 1....";
			wait(1);
			
			
			//hide the text
			renderer.enabled = false;
			
			
			//reset ball
			ball.GetComponent(BallBehaviour).Reset();
			
			//start the game
			Time.timeScale = 1;
			}
}

But this solution leads Unity to actually freeze and I need to kill Unity form proccesses.

I’ve been experimenting with: yield WaitForSeconds(), but that doesn’t work either for my problem.

Any idea how to solve it?

Instead of using while() loop or corutines with such simple time management you should use your Update() method to check time differences and set everything for you.

public string[] countdown = new string[5] {
    "Get ready in 5....", "Get ready in 4....",
    "Get ready in 3....", "Get ready in 2....",
    "Get ready in 1...." };

public float TextDelay = 1.0f;
public bool timeSet = false;
public int showID;
public float timer;

void Update(){ StartCounting(); }

void StartCounting()
{
    if(!timeSet)
    {
        timeSet = true;
        timer = Time.time + TextDelay;
    }
    else
    {
        if(Time.time >= timer)
        {
            myText.text = countdown[showID];
            timeSet = false;
            showID++;
        }
    }
}