Starter Kit Script Reference

Every C# script across the three Unity 6 starter kits, with what it does and the main concept it teaches. All runtime scripts are namespaced per kit (UIToolkitStarterKit, InputSystemStarterKit, EnemyAIStarterKit); editor scripts live in Editor/ subfolders and never ship in builds.


UI Toolkit Starter Kit

(Plus two non-script assets the scripts drive: HUD.uxml — the UI layout — and StarterKit.uss — all styling, button states, and transitions.)

Script Path What it does
HealthScoreSystem Scripts/ The model: holds health and score, clamps values, and fires C# events (HealthChanged, ScoreChanged) when they change. Contains zero UI code — teaches model/view separation.
HUDController Scripts/ The view: grabs the UIDocument's root, queries elements by name (root.Q<T>()), forwards button clicks and slider changes to the model, and repaints labels/bars when the model's events fire. Also drives USS classes from code (low-health red bar, score "pop").
StarterKitSetup (editor) Scripts/Editor/ Adds Tools → UI Toolkit Starter Kit menu items. Creates the Panel Settings asset and runtime theme (.tss) if missing, then builds a ready-to-play HUD GameObject (UIDocument + both scripts, wired) in the current scene.

Input System Starter Kit

(Plus StarterKitControls.inputactions — the shared actions asset with Player2D, Player3D, and Puzzle maps, bound for keyboard/mouse and gamepad. Every script below reads from it.)

Script Path What it does
PlayerController2D Scripts/Platformer2D/ Side-scroller movement on a Rigidbody2D: polls Move, uses Jump's performed/canceled events for jump buffering and variable jump height, plus coyote time and a ground BoxCast. Teaches the poll-values / subscribe-to-moments pattern.
FirstPersonController Scripts/FirstPerson/ FPS move/look/jump/sprint on a CharacterController. Everything is polled (ReadValue, WasPressedThisFrame) as the counterpart to the 2D script's events. Contains the kit's one device branch: mouse-delta vs stick sensitivity via activeControl.
WeaponSwitcher Scripts/FirstPerson/ Weapon slots and firing: scroll-wheel up/down and shoulder buttons cycle weapons, 1/2/3 jump to slots (subscribed in a loop with a captured-index lambda), and Fire hitscan-raycasts from screen center, painting what it hits.
DragAndDropController Scripts/Puzzle/ Pointer drag-and-drop: one Point action fed by mouse, pen, and touch; Click.started/canceled as press/release; screen→world conversion; snap-to-nearest-free-slot on release; Esc/B cancels the drag.
SelectionCycler Scripts/Puzzle/ Keyboard/gamepad selection cycling (Tab/E/Q, shoulder buttons) with scale+opacity highlight — the no-pointer accessibility path through the puzzle demo.
Draggable Scripts/Puzzle/ Tiny marker component: makes an object grabbable, remembers its home position and which slot it occupies, and can ReturnHome().
SnapSlot Scripts/Puzzle/ Tiny drop-target component: a snap radius and an occupancy flag, with a gizmo showing the radius.
InputKitSetup (editor) Scripts/Editor/ Adds Tools → Input System Starter Kit menu items that build all three playable demo rigs from primitives — generating a white square sprite and pipeline-agnostic materials on demand. If the Input System package is missing, a fallback menu item shows install help instead.

Enemy AI Starter Kit

Script Path What it does
TargetSensor Scripts/Enemy3D/ Reusable detector answering "can I detect the target?": range check → field-of-view cone → line-of-sight linecast, cheapest first, each toggleable. The 3D enemy carries two — long-range vision (12u/110°/LOS) and short-range attack reach (2.2u/360°). Draws its ranges as gizmos.
EnemyAI3D Scripts/Enemy3D/ The 3D brain: a Patrol → Chase → Attack finite state machine on a NavMeshAgent. Patrols waypoints with idle pauses, chases via SetDestination, attacks on a cooldown while facing the player, and returns to the nearest patrol point after a 3-second lose-sight timer.
GridPathfinder2D Scripts/TopDown2D/ A complete, readable A* implementation (~150 lines). Bakes a walkability grid from static colliders (anything without a Rigidbody2D), then FindPath() returns a world-space route with octile heuristic, no corner cutting, and nearest-walkable goal fallback. One instance serves all enemies.
EnemyAI2D Scripts/TopDown2D/ The top-down brain: deliberately the same FSM as EnemyAI3D, but the movement layer follows A* paths node-by-node and detection is radius + wall-blocking linecast. Repaths on a 0.5 s timer while chasing. Side-by-side comparison with the 3D script is the kit's core design lesson.
PlatformerEnemy2D Scripts/Platformer2D/ The "smarter than back-and-forth" patroller: wall and ledge raycast feelers (patrols any platform unedited), forward-only vision with height band and LOS, an alert telegraph pause before charging, edge-aware chasing that never walks off cliffs, and a give-up leash. States: Patrol → Alert → Chase → Attack.
DamageFlash Scripts/Common/ Feedback helper: flashes a Renderer or SpriteRenderer red for a moment. Enemies call it on the player when they attack — the marked stand-in for a real damage system.
DemoPlayer3D Scripts/Common/ Minimal WASD CharacterController mover so the enemy has prey. Reads the keyboard directly under either input backend — deliberately not an input lesson, just a zero-dependency demo driver.
DemoPlayer2D Scripts/Common/ Same idea in 2D, with two inspector-selectable modes: TopDown (4-way, no gravity) and Platformer (run + jump + gravity).
FollowCamera Scripts/Common/ Smoothly follows a target from a fixed offset, always looking at it — lets you watch the 3D chase unfold.
EnemyKitSetup (editor) Scripts/Editor/ Adds Tools → Enemy AI Starter Kit menu items building all three demo arenas from primitives. Bakes the NavMesh automatically (via reflection so the kit compiles without the AI Navigation package), baking the level before spawning characters, and persists the baked data as an asset.

Cross-kit patterns (what repeats on purpose)