UI Setup: LapPositionBarUI
The LapPositionBarUI gives players an at-a-glance horizontal mini-map of where every competitor is on the track.
Prerequisites
- A
RaceTimingManagerexisting in the scene. - A
CompetitorFocusManagerexisting in the scene (controls which dot is highlighted green). - Track markers must be configured (the system needs to know track length to calculate relative lap positions).
Setup from Prefab (Recommended)
The easiest way to get the Lap Position Bar is to drag the pre-built prefab into your Canvas.
- Ensure you have a standard Unity Canvas in your scene.
- Navigate to
Assets/SlowToastRacing/RaceTiming/UI/Prefabs/ - Drag the
LapPositionBarUIprefab as a child of your Canvas. - Adjust the Rect Transform on the root
LapPositionBarUIobject to place it where you want (e.g., top centre of the screen).
[!TIP] The
LapPositionBarUIcomponent manages a pool of dots. It will automatically spawn neutral grey dots for opponents, a red dot for the race leader, and a green dot for the currently focused competitor. Wait until runtime to see them appear!
Manual Setup (Custom UI)
If you prefer building the UI from absolute scratch:
- Create an empty GameObject under your Canvas and name it
CustomLapPositionBar. - Add the
LapPositionBarUIcomponent. - In the Inspector, configure your colours:
- Leader Color: (e.g., Red)
- Focused Color: (e.g., Green)
- Default Color: (e.g., Grey)
- Assign a Dot Sprite (e.g., the default Unity 'Knob' for a circle, or leave empty for squares).
- Set the Initial Pool Size high enough to cover your maximum expected grid size (default is 30).
- Provide a Dot Container. This is the
RectTransformarea where the dots will slide left to right. It should be as wide as you want the bar to be.
Changing Focus at Runtime
To change which car gets the green "Focused" dot, simply update the CompetitorFocusManager:
// Focus on Car 5
CompetitorFocusManager.Instance.SetFocus(5);