A modular, physics-driven 2D clone of the classic Flappy Bird arcade game. Built from scratch in Unity using C# and styled using the Universal Render Pipeline (URP). This project illustrates core game design patterns, responsive physics controls, procedural generation, and optimized resource cleanup.
- Objective: Fly the bird through the gaps between the green pipes without crashing.
- Control: Press the
Spacebarto flap upward. - Score: Earn 1 point for every set of pipes successfully passed.
- Game Over: Triggered instantly upon colliding with any pipe, falling below the screen, or flying too high. Press the UI buttons to restart.
- Engine: Unity 6 / Modern Unity LTS
- Language: C# (Object-Oriented Programming)
- Rendering: Universal Render Pipeline (URP)
- Physics: 2D Rigidbodies with dynamic impulse forces, trigger colliders, and collision listeners.
- UI System: Unity UI Canvas for scoring and game-over panels.
graph TD
Player[BirdScript] -->|Spacebar Flap| Physics[Rigidbody2D]
Player -->|Collides / Exits Bounds| Logic[LogicScript]
Spawner[PipeSpawnScript] -->|Timer Check| Instantiate[Pipe Prefab]
Instantiate -->|Constant Leftward Move| Movement[PipeMoveScript]
Movement -->|Out of Screen Bounds| Destroy[Destroy Asset]
Trigger[PipeMiddleScript] -->|Player Enters Gap| Logic
Logic -->|Score Increment| UI[Canvas ScoreText]
Logic -->|Game Over| UI2[GameOverPanel]
The project structure keeps logic neatly encapsulated into separate behaviors:
- Manages player input, applying an instantaneous velocity impulse to the
Rigidbody2Dupon pressing theSpacebar. - Performs boundary checks (
transform.position.yconstraints) to ensure the player cannot fly off-screen indefinitely. - Listens to standard physics collisions (
OnCollisionEnter2D) to trigger game-over sequences.
- Acts as the centralized state manager for the active level.
- Manages the player's score and dynamically updates the HUD.
- Controls UI visibility (toggling the game-over screen overlay) and handles scene reloads via the
SceneManager.
- Periodically spawns the Pipe prefab at the right-hand edge of the viewport.
- Combines a simple cooldown timer with random vertical offsets (
Random.Range) to generate unpredictable obstacles.
- Translates spawned pipe obstacles from right to left using frame-rate independent physics (
Time.deltaTime). - Implements automatic cleanup: once a pipe object travels past the left threshold (i.e.
x < -30), it deletes itself to prevent memory leaks.
- Attached to a trigger collider positioned in the gap between the upper and lower pipes.
- Listens for the player bird entering this boundary to increment the player's score.
- Make sure you have Unity Hub and a compatible Unity Editor version installed.
- Clone or download this repository.
- Open Unity Hub, click Add, and select the
Flappy Birdfolder. - Once the project loads in the Editor, navigate to
Assets/Scenesand open the main scene. - Press the Play button at the top of the editor window.
Here are a few additions that can take this simple project to the next level:
- Audio Effects: Add sound effects for flapping, scoring, and crashing, along with background music.
- Visual Enhancements: Add a parallax scrolling background (skyline, clouds, grass) and particle effects on flap.
- Mobile Support: Bind controls to touch screen input (
Input.touchCountor the new Input System). - Persistent High Scores: Save the user's best score locally using
PlayerPrefs. - Progressive Difficulty: Gradually increase pipe movement speed or decrease the spawn interval as the player's score rises.