Time for action – preparing the clock code
Let's rough in a few empty functions and three variables that we'll need to make the clock work.
Open up the ClockScript by double-clicking on it. Update the code:
#pragma strict var clockIsPaused : boolean = false; var startTime : float; //(in seconds) var timeRemaining : float; //(in seconds) function Awake() { } function Update() { if (!clockIsPaused) { // make sure the timer is not paused DoCountdown(); } } function DoCountdown() { } function PauseClock() { clockIsPaused = true; } function UnpauseClock() { clockIsPaused = false; } function ShowTime() { } function TimeIsUp() { }
What just happened – that's a whole lotta nothing
Here, we've created a list of functions that we'll probably need to get our clock working. The functions are mostly empty, but that's okay—roughing them in like this is a really valid and useful way to program. We have a DoCountdown()
function that we call on every update, as long as our clockIsPaused...