Menu
CoddyTech

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 icon

Challenge

Easy

Write the dashboard in Dashboard.cs.

  1. In Update(), show car.speed * 3.6f as whole km/h, 54 km/h, red above 50 and white otherwise.
  2. Keep the top km/h in a field; show it as Top: 61 km/h.
  3. Each frame, add car.speed * Time.deltaTime to 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
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Building Real Games

Practice on your own: Unity playground