Skip to content

UI & Input

This page describes how player input is handled and how the UI is connected to gameplay systems.


Selection flow

UnitSelectionController

Handles low-level mouse logic:

  • Left click on world:
  • Raycast to selectable objects (units / buildings)
  • Call into SelectableManager to update selection
  • Left click drag:
  • Draw a selection rectangle
  • Multi-select units inside the rectangle
  • Right click:
  • Raycast to ground or attackable targets
  • Issue move or attack commands to all currently selected units

Important fields:

  • unitLayerMask → which layers are considered selectable player units
  • groundLayerMask → ground layers for movement commands
  • attackTargetMask → layers that can be attacked

SelectableManager

Acts as the single source of truth for selection:

  • Current building
  • Current unit (primary)
  • CurrentUnits (multi-selection list)

Raises events when selection changes.
UI panels subscribe to these events to update what they display.


Building UI

BuildingUIManager

Responsible for:

  • Showing building information panel when a building is selected
  • Showing unit information panel(s) when units are selected
  • Displaying production buttons for buildings that can produce units
  • Displaying worker assignment buttons for buildings that support workers

Flow:

  1. Subscribes to SelectableManager events.
  2. When a building is selected:
  3. Clears existing UI elements
  4. Instantiates building info widgets
  5. Shows buttons for available production / worker actions
  6. When units are selected:
  7. Clears building UI elements
  8. Instantiates one info widget per unit (SelectedUnitInfoUI).

SelectedUnitInfoUI

Displays:

  • Icon
  • Name
  • Health bar
  • Optional numeric health text

Binds to a Damageable target and listens to:

  • OnHealthChanged → update health bar & text
  • OnDied → destroy the UI widget automatically

This guarantees that taking damage updates the UI and dead units are removed from the info panel.


World-space health bars

Units and buildings can also have world-space health bars:

  • A small Canvas in World Space mode as a child of the object
  • A Slider inside it
  • A WorldHealthBar component that subscribes to Damageable.OnHealthChanged

The WorldHealthBar rotates the canvas to face the camera so the health bar is readable from most angles.