Skip to content

nulllvector/flappybird-unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flappy Bird 2D (Unity Clone)

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.


🎮 Gameplay & Controls

  • Objective: Fly the bird through the gaps between the green pipes without crashing.
  • Control: Press the Spacebar to 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.

🛠️ Tech Stack & Architecture

  • 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.

Component Diagram

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]
Loading

📂 Codebase Breakdown

The project structure keeps logic neatly encapsulated into separate behaviors:

1. BirdScript.cs

  • Manages player input, applying an instantaneous velocity impulse to the Rigidbody2D upon pressing the Spacebar.
  • Performs boundary checks (transform.position.y constraints) to ensure the player cannot fly off-screen indefinitely.
  • Listens to standard physics collisions (OnCollisionEnter2D) to trigger game-over sequences.

2. LogicScript.cs

  • 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.

3. PipeSpawnScript.cs

  • 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.

4. PipeMoveScript.cs

  • 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.

5. PipeMiddleScript.cs

  • 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.

⚙️ How to Open & Run

  1. Make sure you have Unity Hub and a compatible Unity Editor version installed.
  2. Clone or download this repository.
  3. Open Unity Hub, click Add, and select the Flappy Bird folder.
  4. Once the project loads in the Editor, navigate to Assets/Scenes and open the main scene.
  5. Press the Play button at the top of the editor window.

🔮 Roadmap / Future Improvements

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.touchCount or 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.

About

A classic 2D Flappy Bird clone developed in Unity using C#. Implements physics-based player mechanics, dynamic procedural obstacle spawning, and efficient object lifecycle management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages