Recap: Speedometer
Part of the Building Real Games section of Coddy's Unity journey. Lesson 5 of 56.
Challenge
EasyThe test car is driven by Car.cs, which is finished: the up arrow speeds it up, the down arrow brakes, and its public speed is in meters per second. Write the dashboard in Dashboard.cs (the scene links car, speedText, topText and tripText):
speedTextshows the speed in km/h (meters per second times 3.6), rounded to a whole number:54 km/h. It is red above 50 km/h and white otherwise.topTextshows the highest speed reached so far, the same way:Top: 61 km/h. Braking does not lower it.tripTextshows the distance driven so far, in kilometers with two decimals:Trip: 0.18 km. Add up the meters the car covers each frame.
Press Play, speed up past 50, brake, then Check.
Try it yourself
using UnityEngine;
using TMPro;
public class Dashboard : MonoBehaviour
{
public Car car;
public TMP_Text speedText;
public TMP_Text topText;
public TMP_Text tripText;
// Show the speed, the top speed and the trip
}
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