Recap: Speedometer
Part of the Building Real Games section of Coddy's Unity journey. Lesson 5 of 60.
This chapter put numbers on screen: a text field, a value joined to a string, formats after a colon, and a timer worked out every frame. The dashboard uses all of them.
Challenge
EasyWrite the dashboard in Dashboard.cs.
- In
Update(), showcar.speed * 3.6fas whole km/h,54 km/h, red above 50 and white otherwise. - Keep the top km/h in a field; show it as
Top: 61 km/h. - Each frame, add
car.speed * Time.deltaTimeto a trip field; show it in km with two decimals:Trip: 0.18 km.
Press Play, speed up and brake: the top speed stays. 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
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
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