Menu
CoddyTech

Speeding Up

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

challenge icon

Challenge

Medium

Speed the road up, with the speed kept in GameManager.

  1. In GameManager, add public static GameManager Instance; and set Instance = this; in Awake().
  2. In its Update(): speed = Mathf.Min(speed + speedUp * Time.deltaTime, maxSpeed);.
  3. In Obstacle, delete the speed field and move at GameManager.Instance.speed, read every frame.

Press Play: the obstacles come faster and faster. Then Check.

Try it yourself

using UnityEngine;

public class GameManager : MonoBehaviour
{
    public float speed = 10f;
    public float speedUp = 0.5f;
    public float maxSpeed = 20f;

    // Make this a singleton, and speed the road up every frame
}

All lessons in Building Real Games

Practice on your own: Unity playground