SETUP_INSTRUCTIONS.md 6.2 KB

Hockey Game UI and Timer System

This update adds a UI Builder scoreboard with timer control and a "puck in play" system that controls when the timer runs and when players can move.

Features Implemented

1. GameManager (Central Game Control)

  • Manages game time (countdown from 20:00)
  • Tracks home/away scores
  • Controls period tracking
  • Puck In Play Control: Timer only runs when puck is in play
  • Events system for UI updates

2. UI System (UI Toolkit/UI Builder)

  • Scoreboard Layout: "Home Team" 0 | Timer | 0 "Away Team"
  • Real-time score updates
  • Countdown timer display (MM:SS format)
  • Period indicator
  • Styled with professional hockey scoreboard look

3. Faceoff Integration

  • Timer stops during faceoffs
  • Players are frozen until faceoff resolves to:
    • HomeWin
    • AwayWin
    • Struggle
  • Timer starts automatically when puck is in play

4. Player Movement Control

  • Both human and AI players respect "puck in play" state
  • No movement during faceoffs
  • Smooth deceleration when frozen

Setup Instructions

Step 1: Add GameManager

  1. In your scene, create an empty GameObject
  2. Name it "GameManager"
  3. Add the GameManager component
  4. Configure settings (optional):
    • Period Duration: 1200 seconds (20:00)
    • Total Periods: 3

Step 2: Setup UI

  1. Create an empty GameObject named "GameUI"
  2. Add UIDocument component
  3. Configure UIDocument:
    • Source Asset: Select Assets/UI/GameUI.uxml
    • Panel Settings: Create or use existing Panel Settings (see Step 3)
  4. Add UIController component to the same GameObject
  5. In UIController, set:
    • Home Team Name: "Home Team" (or your team name)
    • Away Team Name: "Away Team" (or your team name)

Step 3: Create Panel Settings (if needed)

  1. Right-click in Project window
  2. Select: Create > UI Toolkit > Panel Settings Asset
  3. Name it "GameUIPanelSettings"
  4. Configure:
    • Scale Mode: Scale With Screen Size
    • Reference Resolution: 1920 x 1080
    • Screen Match Mode: Match Width Or Height
    • Match: 0.5 (balance between width and height)
  5. Assign this Panel Settings to your UIDocument component

Step 4: Link FaceoffManager (if not already linked)

Your existing FaceoffManager is already updated to work with the new system. It will automatically:

  • Set puck in play to false when faceoff starts
  • Set puck in play to true when faceoff completes
  • Freeze all players during faceoffs

Step 5: Test the System

  1. Press Play in Unity
  2. Press F to trigger a faceoff at center ice
  3. Observe:
    • Timer stops
    • Players freeze
    • Faceoff resolves after ~2 seconds
    • Timer starts counting down
    • Players can move

How It Works

Puck In Play Flow

Game Starts
    ↓
Timer: 20:00, Puck In Play: FALSE
    ↓
Press F (Faceoff Starts)
    ↓
Freeze Players, Timer Stays Paused
    ↓
Faceoff Resolves (HomeWin/AwayWin/Struggle)
    ↓
Puck In Play: TRUE
    ↓
Timer Counts Down, Players Can Move
    ↓
Goal Scored
    ↓
Puck In Play: FALSE (new faceoff needed)

Key Scripts

GameManager.cs

  • Singleton pattern
  • Controls game state
  • Manages timer countdown
  • Score tracking
  • Event broadcasting

UIController.cs

  • Subscribes to GameManager events
  • Updates UI labels in real-time
  • Formats time display

FaceoffManager.cs (Updated)

  • Signals GameManager when faceoff starts/ends
  • Controls puck in play state

PlayerMovement.cs (Updated)

  • Checks GameManager.Instance.IsPuckInPlay
  • Stops player input when false
  • Applies deceleration

PlayerAIMovement.cs (Updated)

  • Checks GameManager.Instance.IsPuckInPlay
  • Stops AI decisions when false
  • Stops AI movement when false

Testing Checklist

  • GameManager exists in scene
  • UI displays correctly at top of screen
  • Timer shows "20:00" at start
  • Period shows "Period 1"
  • Scores show "0 - 0"
  • Press F to start faceoff
  • Timer remains at 20:00 during faceoff
  • Players cannot move during faceoff
  • After faceoff completes, timer counts down
  • Players can move after faceoff
  • Score updates work (test manually via GameManager.Instance.AddHomeScore(1))

Customization

Change Team Names

In UIController component:

  • Home Team Name: Enter your home team name
  • Away Team Name: Enter your away team name

Change Period Duration

In GameManager component:

  • Period Duration: Set in seconds (1200 = 20:00)

Style Modifications

Edit Assets/UI/GameUI.uss to customize:

  • Colors (background, text, scores)
  • Font sizes
  • Spacing and padding
  • Border styles

Add Goal Detection

To automatically trigger scoring when puck enters net:

// In your goal detection script:
if (GameManager.Instance != null)
{
    if (isHomeGoal)
        GameManager.Instance.AddAwayScore();
    else
        GameManager.Instance.AddHomeScore();
}

Files Created/Modified

New Files

  • Assets/Scripts/GameManager.cs - Main game controller
  • Assets/Scripts/UIController.cs - UI manager
  • Assets/UI/GameUI.uxml - UI layout
  • Assets/UI/GameUI.uss - UI styles
  • Assets/UI/SETUP_INSTRUCTIONS.md - This file

Modified Files

  • Assets/Scripts/FaceoffManager.cs - Added GameManager integration
  • Assets/Scripts/Player/PlayerMovement.cs - Added puck in play check
  • Assets/Scripts/Player/AI/PlayerAIMovement.cs - Added puck in play check
  • Assets/Scripts/MainGameScript.cs - Added setup documentation

Troubleshooting

Timer not counting down

  • Check GameManager exists in scene
  • Verify faceoff has completed (press F and wait)
  • Check Console for "Puck in play: True" message

UI not showing

  • Verify UIDocument has GameUI.uxml assigned
  • Check Panel Settings is assigned
  • Ensure UIDocument has UIController component
  • Check Canvas scale mode

Players still moving during faceoff

  • Verify GameManager.Instance is not null
  • Check FaceoffManager is calling SetPuckInPlay
  • Verify PlayerMovement/PlayerAIMovement have been updated

Events not firing

  • Ensure only ONE GameManager exists in scene
  • Check UIController OnEnable is subscribing to events
  • Verify GameManager.Instance is accessible

Future Enhancements

Possible additions:

  • Pause menu integration
  • Overtime periods
  • Shot clock
  • Penalty timer display
  • Replay last goal
  • Game statistics