Scene Overview
The game consists of three Unity scenes that handle the complete game flow:Scene Flow
The game follows a linear scene progression:- Title - Player starts the game
- Gameplay - Player navigates the platformer level
- Ending - Shows final score and offers replay options
Scene Management Scripts
All scene logic is located inAssets/Scripts/SceneLogic/ and handles scene transitions and game state management.
MainMenu.cs
Location:Assets/Scripts/SceneLogic/MainMenu.cs:4
Handles the title screen and game initialization.
- Provides
StartGame()method called by UI button - Transitions from Title scene to Gameplay scene
- Simple, stateless scene transition
FinishGame.cs
Location:Assets/Scripts/SceneLogic/FinishGame.cs:6
Handles level completion and player death scenarios using an event-driven approach.
- Detects level completion (reaching finish line)
- Handles player death (collision with spikes or fall detection)
- Broadcasts events for death and completion
- Manages transition delay for death feedback (0.75s)
- Transitions to Ending scene
Event-Driven Architecture
Event-Driven Architecture
The script uses C# events to notify other systems:
OnDeathEvent- Triggered when player dies (used byMusicManager.cs:16andScoreSystem.cs:14)OnFinishedEvent- Triggered on successful completion (used byScoreSystem.cs:15)
Death Handling
Death Handling
When the player dies:
- Collision detected with “Spike” or “DeathDetector” tag
OnDeathEventis invoked (triggers death sound)- 0.75-second delay allows feedback to play
- Scene transitions to Ending
Collision-Based Triggers
Collision-Based Triggers
Attached to multiple GameObjects:
- Finish line trigger (success path)
- Spike obstacles (death path)
- Fall detection zone (death path)
ResetGame.cs
Location:Assets/Scripts/SceneLogic/ResetGame.cs:4
Provides gameplay restart functionality from the ending screen.
- Reloads Gameplay scene for replay
- Called by “Try Again” or “Replay” button
- Resets all gameplay state by reloading the scene
QuitGame.cs
Location:Assets/Scripts/SceneLogic/QuitGame.cs:4
Handles application exit with editor-safe implementation.
- Exits the application when requested
- Supports ESC key for quick exit
- Can be called by UI buttons
- Editor-safe implementation (stops play mode instead of crashing)
Input System Integration
Input System Integration
Uses Unity’s new Input System (
UnityEngine.InputSystem):- Checks for ESC key press each frame
wasPressedThisFrameensures single trigger per press- Null-checks keyboard to prevent errors
Platform-Specific Exit
Platform-Specific Exit
Conditional compilation for different environments:
- Editor: Stops play mode without crashing Unity
- Build: Properly exits the application
Scene Transition Patterns
The project uses two main patterns for scene transitions:Direct Loading
Immediate scene transitions for instant feedback:MainMenu.cs- Start gameResetGame.cs- Replay game
Delayed Loading
Transitions with delay for feedback:FinishGame.cs- Death scenario (allows death sound/animation)
Scene Dependencies
Gameplay Scene
Requires these active systems:- Player GameObject with
PlayerInputandPlayerJumpcomponents ScoreSystemfor tracking collected coinsMusicManagerfor audio feedbackCameraControllerfor camera following- Finish line with
FinishGamecomponent - Obstacles with
FinishGamecomponent (tagged “Spike” or “DeathDetector”)
Ending Scene
Dependencies:ShowFinalScorescript to displayScoreSystem.FinalScore- UI buttons connected to
ResetGame.ResetGameToGameplay() - Optional quit button connected to
QuitGame.Quit()
Title Scene
Minimal dependencies:- UI button connected to
MainMenu.StartGame() - Optional
QuitGamecomponent for ESC key handling