Minimal Pong (Unity / C#)
A runnable, three-script Pong built as the step-1 project in overview-arcade-classics-as-learning-projects. It isolates the skills that project teaches first: continuous movement, the game loop, manual collision and reflection, basic input, and a single score-owning controller.
It is deliberately not a clone of Atari’s Pong — it uses plain squares and original naming. Treat the original as a design reference, not something to copy.
Files
| Script | Responsibility | Key wiki concept |
|---|---|---|
Ball2D.cs | Moves the ball, reflects off walls and paddles, raises a Scored event | reflection, unity-collider2d-and-triggers |
Paddle2D.cs | Player input or a beatable “track the ball” AI, clamped to screen | unity-input, unity-transform |
PongMatch.cs | Owns the score, serves and re-serves the ball | unity-gamemanager-pattern, observer-pattern |
ArcadeHud.cs (in ../shared/) | Shared on-screen HUD: a status line plus a timed centre message, drawn with TextMeshPro | ui-design, game-interface-types |
No Rigidbody2D is used. Collision and reflection are written out by hand on purpose — making them explicit is the learning goal of a first project.
Scene setup (about 5 minutes)
- New 2D scene. Set the Main Camera to Orthographic (the scripts read
orthographicSizeandaspectto find the play-area edges). - Create three square sprites (
GameObject → 2D Object → Sprites → Square):Ballat the origin.LeftPaddlenear the left edge,RightPaddlenear the right edge. Scale each to a tall thin bar (e.g. scale0.3, 2, 1).
- Add a Box Collider 2D to each paddle (used only for its
bounds— no Rigidbody, no physics material needed). - On
Ball, addBall2Dand drag both paddle colliders into the Paddles array. - On
LeftPaddle, addPaddle2Dwith Control Mode = Player. OnRightPaddle, addPaddle2Dwith Control Mode = Ai and drag theBalltransform into the Ball field. - Create an empty
MatchGameObject, addPongMatch, and dragBallinto its Ball field. - HUD: copy
../shared/ArcadeHud.csinto the project as well. Add GameObject → UI → Text - TextMeshPro (click Import TMP Essentials the first time). Unity also creates a Canvas (leave it on Screen Space - Overlay) and an EventSystem. Name the textStatusTextand anchor it to the top-centre; duplicate it asMessageText, anchor it to the centre, and set its alignment to centre. AddArcadeHudto the Canvas, drag both texts into its Status Text and Message Text fields, then drag the Canvas into the Hud field onMatch. (Leave Hud empty and messages print to the Console instead.) - Press Play. Move the left paddle with W/S or the up/down arrows; the right paddle tracks the ball. The score shows at the top of the screen, and the winner is announced in the centre.
For two human players, set the right paddle to Player and give it a custom vertical axis (Edit → Project Settings → Input Manager), then put that axis name in its Vertical Axis field.
Extension ladder
These mirror the Pong extension tasks in the canon reference (see source-classic-games-canon) and lead naturally toward step 2 (Breakout):
- Sound and screen shake on hit — the cheapest possible game-feel win; see unity-audiosource.
- Difficulty scaling — raise
aiResponsivenessorstartSpeedas the rally grows. (Introduces difficulty tuning, the core of Breakout.) - Serve countdown — pause briefly before each serve using a coroutine.
- Swap to Rigidbody2D — re-implement the bounce with physics and a Bouncy 2D material to compare the two approaches; see unity-rigidbody2d and transform-vs-rigidbody2d-movement.