O'Reilly logo

Unity 3D Game Development by Example by Ryan Henson Creighton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - display the time on-screen

We know from the Debug statements that the clock is working, so all we need to do is stick the timeRemaining value into our GUIText. But, it won't look very clock-like unless we perform a tiny bit of math on that value to split it into minutes and seconds so that five seconds displays as 0:05, or 119 seconds displays as 1:59.

  1. Call the ShowTime() function from within the DoCountdown() function (you can delete the Debug.Log statement):
    function DoCountdown()
    {
    timeRemaining = startTime - Time.time;
    // (other lines omitted for clarity)
    ShowTime();
    Debug.Log("time remaining = " + timeRemaining);
    }
    
  2. Create some variables to store the minutes and seconds values in the ShowTime() function, along with a variable ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required