04 — Building the HUD
Time to build the kit's HUD yourself. Work in a new UXML file (Assets → Create → UI Toolkit → UI Document, name it MyHUD.uxml) so you can compare against the finished HUD.uxml whenever you get stuck.
Step 1 — Root container
- Drag a VisualElement from the Library into the Hierarchy. Name it
hud-root. - Inspector → Flex → Grow = 1 so it fills the screen. Give it Padding = 24 on all sides.
- Justify Content = space-between — top bar goes up, buttons go down, automatically.
Step 2 — Score counter (text + numbers)
- Inside
hud-root, add a VisualElement namedtop-bar. Set Direction = Row, Justify Content = flex-end. - Inside it, add a Label named
score-label, textScore: 0. - Font size ~32, bold. (We'll move these into a class in 05 - Styling and Button States.)
A score counter is just a Label — C# will rewrite its text every time the score changes.
Step 3 — Health bar (slider + progress bar)
- Inside
hud-root, add a VisualElement namedleft-column, width 380. - Add a VisualElement named
health-panelinside it — this is our first "panel". Add a Label ("Health") as a title. - Add a ProgressBar named
health-bar. Set High Value = 100, Value = 100, Title100 / 100. - Add a Slider named
health-slider, High Value = 100, Value = 100, labelDebug Health.
Why both? A ProgressBar is display-only — the right choice for showing health. A Slider is input — dragging it lets you test any health value instantly. Shipping both teaches the difference between output controls and input controls, and the slider becomes your live debug tool.
Step 4 — Description panel (wrapped text)
- Below
health-panel, add a VisualElement nameddescription-panel. - Inside: a Label named
description-titleand a second Label nameddescription-bodywith a couple of sentences of text. - On
description-body, set White Space = Normal (Inspector → Text). Without this, Labels never wrap — the #1 beginner question.
Step 5 — Buttons
- Inside
hud-root, add a VisualElementbutton-row, Direction = Row, Justify Content = center. - Add four Buttons:
damage-button("Take Damage"),heal-button("Heal"),score-button("+10 Score"),locked-button("Locked").
They look flat and gray for now — states and colors come from USS in the next lesson.
Step 6 — Settings row (the other useful controls)
Add a VisualElement settings-row (Direction = Row) at the bottom containing:
- Toggle named
godmode-toggle, label "God Mode" — a checkbox - DropdownField named
difficulty-dropdown, label "Difficulty", choicesEasy,Normal,Hard - TextField named
player-name-field, label "Player"
Other controls worth knowing that follow the exact same patterns: RadioButtonGroup, MinMaxSlider, Foldout, ScrollView, and ListView (the big one for inventories — see the ListView docs).
Step 7 — Save and show it
Save in UI Builder (Ctrl+S), then point your scene's UIDocument → Source Asset at MyHUD.uxml (or the kit's HUD.uxml). It appears in the Game view immediately — no Play mode needed.