Time for action – displaying 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 to see it on the screen. 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.
Call the
ShowTime()
function from within theDoCountdown()
function (you can delete or comment theDebug.Log()
statement):function DoCountdown() { timeRemaining = startTime - Time.time; // (other lines omitted for clarity) ShowTime(); //Debug.Log("time remaining = " + timeRemaining); }
Create some variables to store the minutes and seconds values in the
ShowTime()
function, along with a variable to store thestring
(text) version of the time:function ShowTime() { var minutes : int; var seconds : int; var timeStr : String; }
Just below that, divide the
timeRemaining
by60
to get the...