Finish Line
Part of the Building Real Games section of Coddy's Unity journey. Lesson 52 of 56.
Challenge
MediumThe 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
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 Swap