How to stop the whole game and count some numbers?

Hi,

At some point in the game I want to stop the whole game and show a number countdown like 40 to zero.

How can I achieve this?

Thanks!

check out Time.scaletime if you have everything moving off deltatime (like you should) everything will pause when you change it to zero. To countdown, use Time.realTimeSinceStartup (all other time will be frozen) and track your own time to make a counter. Once the counter hits zero, change Time.scaleTime back to 1.

To pause everything, set Time.timeScale to zero.

While timeScale is zero, deltaTime is going to always be zero. You’ll need to use Time.realTimeSinceStartup to keep track of time in that case:

startTime = Time.realTimeSinceStartup;

timerTime = Time.realTimeSinceStartup - startTime;

To pause the game, simply use

Time.timeScale = 0 ;//Pause game

And as far as the countdown, you need to look into GUI. But here is the counter for the countdown. Just be sure to instantiate the proper numbers to the screen.

var countdown : float = 40 ;
function Update ( ) // Seconds
{
   if ( countdown > 0 )
   {
      countdown -= 1 * Time.deltaTime ;
   }else{
      Time.timeScale = 1 ; // Unpause game
   }
}

Like I said, you need to generate the GUI code, and then instantiate the GUI objects like so . . .

Instantiate ( GUIObject, Vector3(0.5, 0.5, 0.5), Quaternion.identity )

Good luck, and let me know if you need further assistance .