Time Trial
Part of the Building Real Games section of Coddy's Unity journey. Lesson 58 of 60.
A time trial across a garden. The runner starts at one end with ten seconds on the clock and has to reach the white goal at the far end, around a hedge, before the time runs out. Golden clocks on the way buy a few more seconds each. When the time is nearly gone the clock turns red; when it is gone, the track starts over. Reach the goal in time and the game moves on to the Finish scene.
Write two scripts: Runner on the runner, a CharacterController, and Race on the Race object.
Challenge
HardWrite Runner and Race.
Runner: Move runs it atspeedwithcontroller.Moveandgravity; aClocktrigger is destroyed and addsbonus,Goalfinishes.Race: time starts attimeLimit, drops byTime.deltaTime, showsTime: 7.4, red under 3.- At 0, log
Time's up!and reload. At the goal, logFinished with 4.2 s leftand loadFinish.
Press Play: beat the clock. Then Check.
Try it yourself
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
public class Race : MonoBehaviour
{
public float timeLimit = 10f;
public float bonus = 3f;
public TMP_Text timeText;
}
All lessons in Building Real Games
2Buttons and Screens
Buttons and onClickLambdasWiring in the InspectorPanels On and OffHealth BarsRecap: Upgrade Shop5Saving with PlayerPrefs
Save a NumberLoad with a DefaultHigh ScoreSave SettingsRecap: Coins in the Bank3The Game Manager
One Script Runs the GameThe SingletonGame StatesSwitching on the StateRecap: Round Manager6Project: Endless Runner
Three LanesObstacles Ahead9The New Input System
Two Input SystemsKeyboard and MousePressed This FrameInput ActionsRecap: Input SwapPractice on your own: Unity playground