Speeding Up
Part of the Building Real Games section of Coddy's Unity journey. Lesson 29 of 60.
Challenge
MediumSpeed the road up, with the speed kept in GameManager.
- In
GameManager, addpublic static GameManager Instance;and setInstance = this;inAwake(). - In its
Update():speed = Mathf.Min(speed + speedUp * Time.deltaTime, maxSpeed);. - In
Obstacle, delete thespeedfield and move atGameManager.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
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 SwapPractice on your own: Unity playground