LevelCountdown before start 3...2...1 GO!

Hi there,

im making a small Game for Gamedesign class where you have to navigate a sphere through a labyrinth kind of level as fast as you can. So obviously the scene has a timer in it to show you your personal best time for each level.

My problem is i would like to have another timer right at the beginning of the scene
(in the middle of the screen (maybe annimated numbers))
which pause the game and counts from 3 to 0 and then unpause the game so that you can start your jurney through the lab.

I guess the Countdown timer im looking for is similar to a Racing Game type of timer which are shown before the race starts.

thanks in advance :slight_smile:

It’s easy. Just use a coroutine…

    void Start()
    {
        StartCoroutine(Countdown(3));
    }
   
    IEnumerator Countdown(int seconds)
    {
        int count = seconds;
       
        while (count > 0) {
           
            // display something...
            yield return new WaitForSeconds(1);
            count --;
        }
       
        // count down is finished...
        StartGame();
    }

    void StartGame()
    {
        // do something...
    }
2 Likes

thanks for you answer,
but to be honest im a noob in Unity, i dont realy know how to use that script.
I attached it to my player sprite and to my Main_Camera but neither works. It dont stopts the game when the scene is loaded.

This is how i controll my Charakter if it helps

 #pragma strict
public var moveSpeed = 2.0; 
function Update () {
     if (Input.GetMouseButton(0)) {
         var targetPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         targetPos.z = transform.position.z;
         transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
     }
}

i think it didnt work for you because its in C# and your character controller script is in javaScript;

Thank you very much ,it worked perfectly;

how to set a text 1 2 3 go

Declare a text in your script and say public Text CountDown; and then assign your int count to this string. For example;
CountDown.text = count.ToString();

Create a UI text in your Unity and drag and drop it to CountDown text.

You will get more information through this link:
https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/displaying-score-and-text

Hope this helps. Cheers.

text not change

public Text countdowns;
public int timerText;
void Start()
{
StartCoroutine(Countdown(3));
}
void Update()
{
countdowns.text = timerText.ToString();

}
IEnumerator Countdown(int seconds)
{
int count = seconds;

while (count > 0)
{
countdowns.text = timerText.ToString();
yield return new WaitForSeconds(1);
count–;
Debug.LogError(“count” + count);
}
StartGame();
}

timer should work text ui not change??