Menu
CoddyTech

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 icon

Challenge

Hard

Write Runner and Race.

  1. Runner: Move runs it at speed with controller.Move and gravity; a Clock trigger is destroyed and adds bonus, Goal finishes.
  2. Race: time starts at timeLimit, drops by Time.deltaTime, shows Time: 7.4, red under 3.
  3. At 0, log Time's up! and reload. At the goal, log Finished with 4.2 s left and load Finish.

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

Practice on your own: Unity playground