<aside> <img src="/icons/reorder_gray.svg" alt="/icons/reorder_gray.svg" width="40px" />

Navigation

</aside>

🏠 Home Page

Getting Started

Architecture

Level System

Characters & Vehicles

Run Mechanics

World Objects

Boosters & Modifiers

Progression & Economy

UI

Save & Debugging

Modules

Publishing

Reference

💰 Monetization (Ads & IAP)

<aside> 💡 GameController in the Game scene runs the loop of one level: load the level, spawn the launcher, aim, launch, finish and reward.

</aside>

What GameController owns

Awake: building the level

  1. Pick the Level. The index is taken in this order: the Editor override (see Testing in the Editor), then the level id saved by LevelSelectionController, then the Level Index field. An index outside the database falls back to the first level.
  2. Spawn the LevelSetup objects. The launcher, the flag and the record wall are instantiated under the character container. The AimInput that matches LevelSetup.AimInputType is enabled and all the others are disabled.
  3. Load the level scene. The scene of the Level is loaded additively. When it is loaded, LevelSceneController is found in it and initialized with the level id. The launch ramp is spawned at the start point when the LevelSetup has one.
  4. Load the upgrades. ProgressionController.LoadLevel passes the upgrades of the Level Character to UpgradesController.
  5. Spawn the character. The prefab from Character.Prefab is instantiated.
  6. Initialize the UI. UIController initializes the pages and GameController subscribes to their events.

PrepareRun: the start screen state

PrepareRun runs once the level scene is ready and after every restart or reward.

  1. Reset the run state objects, the run coins and the active boosters.
  2. Place the character and the launcher behind the launch point.
  3. Hide the flag, show the record wall and reset the HUD.
  4. Show UIProgression when this is the first visit to the level, otherwise show UIStartScreen.
  5. Set the Start camera state and the run camera settings of the Character.
  6. Start the level music.

Character states

CharacterState controls what the character does:

State Meaning
Idle Standing at the start.
Aiming The player sets the launch.
Launched The run is active and steering is enabled.
Crashed The vehicle hit an obstacle and the character is ejected.
Sinking The character entered water.

Phases and events

Phase Trigger What GameController does
Aim Tap on the start screen character.BeginAim(), show UILaunch, camera state Aim.
Cancel Back button of UILaunch Return to the start screen and the Start camera.
Launch AimInput.OnAimReleased launcher.GetLaunchVelocity() goes to character.Launch, steering is enabled, show UIGame, camera state Run.
Crash PlayerController.OnCrashed Disable steering, move the camera to the crash target.
Splash PlayerController.OnSplashed Freeze the run camera, play water particles and the splash sound.
Run finished PlayerController.OnRunFinished Calculate the reward, show the flag and the record, show UIRunResult after 0.75 seconds.
Level finished PlayerController.OnFinishReached Confetti, freeze the camera, show UILevelComplete after 2.5 seconds.

After the run

Camera states

CameraController switches between four Cinemachine virtual cameras of the Game scene:

State When
Start Start screen.
Aim Aim phase.
Run Launched run.
UpgradeFocus Focus on the vehicle while an upgrade is shown.

The blend between states is defined in the Camera Blends asset in Assets/Project Files/Data. The switch from Run to Start is a cut, so the camera returns to the start point behind the fade overlay.

How to react to a run event

Subscribe to the events of PlayerController, or to the events of the page that you need. Do not edit the flow inside GameController when only a reaction is needed.

character.OnRunFinished += OnRunFinished;
character.OnCrashed += OnCrashed;

Always unsubscribe in OnDestroy, as GameController does.