Menu
CoddyTech

Recap: Speedometer

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

challenge icon

Challenge

Easy

The 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):

  • speedText shows 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.
  • topText shows the highest speed reached so far, the same way: Top: 61 km/h. Braking does not lower it.
  • tripText shows 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