How aslahmohamadbahari/glitch-garden works
This repository is a Unity game project organized around a scene-driven 2D gameplay loop with a small set of reusable gameplay systems and asset libraries.
1. Core application boundary
The project is a Unity app, not a service-based system. The main runtime is defined by Unity scenes, prefabs, scripts, and Resources-loaded content. Most behavior is split between scene objects and reusable prefabbed systems.
2. Primary gameplay model: attackers vs defenders
The gameplay appears to be a lane/defense style loop with two opposing entity families:
• Attackers: Fox and Lizard
• Defenders: Cactus, Gnome, Gravestone, Trophy
These are represented both as prefabs and as dedicated animation/controller assets, suggesting each entity has its own movement/attack state machine.
3. Scene structure and lifecycle flow
The project includes multiple scenes for the full user flow:
• Splash Screen
• Start Screen
• Options Screen
• Blank Level
• Level 1
• Win Screen
• Lose Screen
This indicates a menu-to-level-to-result flow, with the level scenes being separate from the UI/menus.
4. Level orchestration subsystem
The main runtime coordination is likely handled by:
• LevelController
• LevelLoader
• GameTimer
• AttackerSpawner
• DefenderSpawner
These form the control layer that starts levels, advances timers, spawns enemies/units, and transitions to win/lose states.
5. Combat and interaction boundaries
Combat is built around a small set of reusable components:
• Health for survivability
• DamageCollider for hit detection
• Shooter for ranged offense
• Projectile for launched attacks
This suggests defenders and attackers are composed from shared combat primitives rather than having entirely separate combat code paths.
6. Entity hierarchy and specialization
There are base scripts for shared behavior and child scripts for specialization:
• Attacker and Defender are the abstract/base roles
• Fox, Lizard, and Gravestone are specialized behaviors
• Shooter likely powers ranged defenders such as Gnome or Cactus
This separation implies a composition-plus-inheritance model where core role logic is centralized and per-character logic is thin.
7. UI and player interaction layer
The UI is split into prefabs and scripts:
• Main Canvas, Level Complete Canvas, Level Lost Canvas
• Buttons prefab
• DefenderButton
• LivesDisplay
• StarDisplay
• OptionsController
• PlayerPrefsController
This layer handles selection, display, and persistence of player-facing game state rather than gameplay simulation.
8. Progression, feedback, and end-state systems
Several dedicated systems support game flow and feedback:
• LivesDisplay tracks failure conditions
• StarDisplay tracks completion/performance
• LevelLoader handles scene transitions
• Load Sound, Music Player, and result sounds provide audiovisual feedback
These systems are mostly presentation and state-transition oriented, bridging gameplay events to UI and audio.
9. Asset organization by domain
The Assets folder is strongly segmented:
• Animations grouped by Attackers, Defenders, and UI
• Prefabs grouped by Attackers, Defenders, Projectiles, and Core Game
• Resources grouped by Fonts, Images, Sounds, Sprites, and VFX
This is a clean domain-based organization that matches the runtime boundaries of the game.
10. Runtime content loading and persistence
The presence of a Resources folder implies some assets are loaded dynamically at runtime through Unity’s Resources system, especially audio, sprites, and VFX. PlayerPrefsController and BillingMode.json suggest local persistent configuration/state is also part of the runtime model.
11. Visual effects and audio as supporting subsystems
VFX and audio are treated as first-class content, not incidental extras:
• Explosion VFX prefab and material
• Multiple background and event sound files
• Per-character animation controllers
These assets support the game’s feedback loop and likely trigger from combat and level transitions.
12. External/tooling boundaries
This is a standard Unity project with package-managed dependencies, editor/build settings, and project-wide physics/audio/input configuration. The important architecture boundary is between Unity-managed engine systems and the game’s own scripts/prefabs/scenes.
Overall, the architecture is a classic Unity scene-based game: scene flow and UI drive the high-level state, level controllers manage spawning and victory/failure, and individual attackers/defenders are built from shared combat components plus per-character animation and behavior assets.
Main entry points: LevelController.cs Level Controller · Resources Resources · Scripts Combat Core · Sounds Audio
Components 23
Runtime Flow
Scenes and coordination systems that drive the game loop.
- Scene Flow · Splash, menu, level, and result scenes that define the player journey.
Assets/Scenes - Level Controller · Coordinates level state, victory and defeat progression.
Assets/Scripts/LevelController.cs - Level Loader · Handles switching between scenes and loading levels.
Assets/Scripts/LevelLoader.cs - Game Timer · Drives timed progression within a level.
Assets/Scripts/GameTimer.cs - Attacker Spawner · Creates attackers into lanes during gameplay.
Assets/Scripts/AttackerSpawner.cs - Defender Spawner · Instantiates defender units for the player.
Assets/Scripts/DefenderSpawner.cs
Gameplay Systems
Entity roles and combat primitives.
- Attacker · Shared behavior for enemy-side units.
Assets/Scripts/Attacker.cs - Defender · Shared behavior for player-side units.
Assets/Scripts/Defender.cs - Combat Core · Health, damage collider, shooter, and projectile interaction.
Assets/Scripts - Fox & Lizard · Specialized attacker behaviors built on the attacker base role.
Assets/Scripts/Fox.cs - Cactus & Gnome · Ranged defenders and their specialized combat behavior.
Assets/Scripts/Shooter.cs - Gravestone & Trophy · Defender variants with distinct idle or utility behavior.
Assets/Scripts/Gravestone.cs
UI and Options
Menus, HUD, and player-facing state.
- Core UI · Main canvas, buttons, level-complete, and level-lost canvases.
Assets/Prefabs/Core Game - Defender Button · Selects which defender to place.
Assets/Scripts/DefenderButton.cs - Lives Display · Shows remaining lives and failure state.
Assets/Scripts/LivesDisplay.cs - Star Display · Shows level completion and performance stars.
Assets/Scripts/StarDisplay.cs - Options · Controls options screen interactions and settings.
Assets/Scripts/OptionsController.cs - Prefs Controller · Reads and writes player preferences and local config.
Assets/Scripts/PlayerPrefsController.cs
Content Libraries
Prefabs, animations, audio, and VFX grouped by domain.
- Attackers · Fox and lizard prefabs plus their animation controllers.
Assets/Prefabs/Attackers - Defenders · Cactus, gnome, gravestone, and trophy prefabs plus animations.
Assets/Prefabs/Defenders - Projectiles & VFX · Axe and zucchini projectiles, explosion VFX, and related materials.
Assets/Prefabs/Projectiles - Resources · Loaded-at-runtime sounds, sprites, fonts, and billing config.
Assets/Resources - Audio · Music, load sounds, and result/event effects.
Assets/Resources/Sounds
Connections 25
- Scene Flow → Level Loader: enters gameplay · Scenes lead into level loading and transitions.
- Scene Flow → Core UI: hosts UI · Menu and result scenes present the main UI prefabs.
- Level Loader → Level Controller: starts level · Loaded levels are coordinated by the level controller.
- Level Controller → Game Timer: drives · The controller uses time to advance the level state.
- Level Controller → Attacker Spawner: spawns enemies · Level state triggers attacker waves.
- Level Controller → Defender Spawner: places defenders · Level state enables defender placement.
- Level Controller → Lives Display: updates failure · Lives and defeat state feed the HUD.
- Level Controller → Star Display: updates score · Completion and performance feed the star display.
- Core UI → Options: opens settings · Options UI is managed from the menu layer.
- Options → Prefs Controller: persists · Settings are saved through player preferences.
- Defender Button → Defender Spawner: selects unit · UI button chooses which defender to spawn.
- Attacker Spawner → Attackers: instantiates · Spawner creates attacker prefabs into the level.
- Defender Spawner → Defenders: instantiates · Spawner creates defender prefabs onto lanes.
- Attacker → Fox & Lizard: specializes · Fox and lizard behavior extends the attacker role.
- Defender → Cactus & Gnome: specializes · Cactus and gnome behavior extend the defender role.
- Defender → Gravestone & Trophy: specializes · Gravestone and trophy behavior extend the defender role.
- Combat Core → Attacker: used by · Attackers depend on shared combat primitives.
- Combat Core → Defender: used by · Defenders depend on shared combat primitives.
- Combat Core → Projectiles & VFX: drives effects · Damage and projectile interactions trigger impacts and VFX.
- Resources → Audio: contains · Runtime resources include audio assets.
- Resources → Projectiles & VFX: contains · Runtime resources include VFX assets.
- Resources → Attackers: contains sprites · Attacker art assets are organized in Resources.
- Resources → Defenders: contains sprites · Defender art assets are organized in Resources.
- Audio → Level Loader: plays load sound · Scene transitions are backed by load and menu audio.
- Audio → Level Controller: plays feedback · Win and loss progression is supported by audio cues.