Menu
CoddyTech

Speeding Up

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

challenge icon

Challenge

Medium

The road speeds up the longer you run. The speed belongs to the whole game, so it moves into GameManager, and every obstacle reads it from there. Keep everything from the earlier lessons.

In GameManager, which the Inspector gives speed (10), speedUp (0.5) and maxSpeed (20):

  • Make it a singleton: a public static GameManager Instance, set to this script in Awake().
  • Every frame, speed grows by speedUp per second, and never goes above maxSpeed.

In Obstacle:

  • Delete the speed field and move at GameManager.Instance.speed instead. Read it every frame, so the obstacles already on the road speed up too.

Press Play and run until the road is fast, then Check.

Try it yourself

using UnityEngine;

public class GameManager : MonoBehaviour
{
    // Runs the game: the speed, the distance and the crash. Later lessons fill this in.
}

All lessons in Building Real Games