📪Adding Time Trial UI

Guide

How To Add Pre-Built Time Trial UI:

To add in-game UI of relevant time trial data into your project, simply drag the TimeTrialUIManager prefab into your scene.

This will automatically display time trial UI for you, but the data will not be saved. This means that relaunching the game will reset the UI such as personal best lap time.

To add this, see the 'Adding Time Trial Saves' guide.

Modifying TimeTrialUIManager To Make Use Of Your Own UI:

To use your own custom (and much better looking) UI, simply modify the TimeTrialUIManager component to use your own UI elements by changing its references. By default, the TimeTrialUIManager references UI objects from the TimeTrialUI prefab.

[Header("Time Trial UI Elements:")]
[SerializeField] private TextMeshProUGUI currentLapTimeText;
[SerializeField] private TextMeshProUGUI bestLapTimeText;
[SerializeField] private Transform sectorTimeContainer;
[SerializeField] private GameObject sectorTimePrefab;

Creating A Custom Time Trial UI Script:

If you need more flexibility, you can also create a custom script to handle your time trial UI instead. This is slightly more complicated as the LapTimeTrackingObject automatically references the TimeTrialUIManager component so that it works right away.

This is a small change and simply requires changing any references to the TimeTrialUIManager in the LapTimeTrackingObject to make use of your own script instead.

In LapTimeTrackingObject.cs:

// Replace declaration with your own script reference
private TimeTrialUIManager timeTrialUI;

// Replace initialization with own logic
timeTrialUI = FindObjectOfType<TimeTrialUIManager>();

// Change all other references in LapTimeTrackingObject.cs

Time trial data can also be accessed by referencing the LapTimeTrackingObject component on the script where you want to access that data.

See Accessing Time Trial Data and LapTimeTrackingObject sections for more information on how to do this.

What Next?

Last updated