Menu
CoddyTech

Finish Line

Part of the Building Real Games section of Coddy's Unity journey. Lesson 52 of 56.

challenge icon

Challenge

Medium

The course gets a finish: the white gate on the last pad, a trigger with the FinishLine script. The build now has two levels, Level1 and Level2 in that order; Level2 is a short course of its own, with three gems. Keep everything from the earlier lessons.

Fill in FinishLine: when the player (an object with the Player script) enters,

  • log the level's name and the word complete!, such as Level1 complete!;
  • load the next level in the build by its build index. After the last level, load the first one again.

Use build indexes rather than level names, so a Level3 added to the build later needs no change in the code. Press Play, run the course and cross the finish, then Check.

Try it yourself

using UnityEngine;

public class FinishLine : MonoBehaviour
{
    // A later lesson fills this in: the end of the level.
}

All lessons in Building Real Games