To make a Pong game in Unity, build a 2D court with solid wall and paddle colliders, move a Rigidbody2D ball through physics, and use trigger zones at each end to award points. Keep score, serving, pause, and win rules in one round controller. For the score and controls, this tutorial uses uGUI; the exact UI input setup depends on your project’s input handling.
How do I make a Pong game in Unity?
Create a 2D scene containing a camera, two paddles, a ball, court boundaries, and goal zones. Simple sprites or shape objects are enough. Unity’s 2D workflow uses Rigidbody2D for physics-controlled objects and Collider2D components to define collision shapes. A Rigidbody2D puts its GameObject under physics-engine control (Unity: Creating a 2D game).
Build the court and collision shapes
- Add Collider2D components to the paddles and top and bottom walls. These are solid contacts: they should stop the ball from passing through.
- Give the ball a Rigidbody2D and a Collider2D. Keep its movement physics-driven rather than moving its Transform every frame.
- Add a trigger collider just beyond each goal line. A trigger detects a crossing without acting as a physical barrier; Unity calls
OnTriggerEnter2D(Collider2D other)when a collider enters a trigger (Unity: OnTriggerEnter2D).
Set the Rigidbody2D and collider configuration so the ball can contact paddles and walls and enter the goal triggers. If a collision or trigger is not registering, inspect the colliders, Rigidbody2D settings, and the project’s 2D layer collision matrix.
Move paddles within the court
Choose a single input approach for this small project. The example below uses Unity’s legacy Input Manager axes, conventionally named Vertical and Vertical2. Confirm those axes exist in the project, or replace them with bindings from the Input System package; do not combine input APIs without configuring the project’s Active Input Handling accordingly.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problems#1 Best Overall
Attach this script to each paddle, assign its Rigidbody2D, and use the appropriate axis name in the Inspector. Set minY and maxY to keep the paddle within the court. These speed and boundary values are game-design choices, not Unity defaults.
using UnityEngine;
public class PaddleController : MonoBehaviour
{
[SerializeField] Rigidbody2D body;
[SerializeField] string inputAxis = "Vertical";
[SerializeField] float speed = 8f;
[SerializeField] float minY = -3.5f;
[SerializeField] float maxY = 3.5f;
float movement;
void Update()
{
movement = Input.GetAxisRaw(inputAxis);
}
void FixedUpdate()
{
float nextY = Mathf.Clamp(body.position.y + movement * speed * Time.fixedDeltaTime, minY, maxY);
body.MovePosition(new Vector2(body.position.x, nextY));
}
}
Read ordinary player input in Update and apply the physics movement in FixedUpdate. Unity documents FixedUpdate as part of the physics update process (Unity: FixedUpdate).
Rank #2
Launch and rebound the ball
Start the ball from a known position and give its Rigidbody2D an initial direction and speed. Unity 6 documents velocity control through linearVelocity; older editor/API versions may use a different property name, so check the version installed in your project before copying code (Unity 6: Rigidbody2D.linearVelocity).
For a basic serve, choose a horizontal direction and a modest vertical component, then normalize the direction so the selected speed remains consistent:
void Launch(Vector2 direction, float speed)
{
body.linearVelocity = direction.normalized * speed;
}
Call the launch method from your round controller when a round begins. Use ordinary collider contacts for paddle and wall rebounds. If you want the ball’s exit angle to depend on where it struck a paddle, calculate that in your own collision logic; it is custom game behavior, not an automatic Unity Pong rule.
How do I add scoring and round control?
Centralize round decisions in one controller instead of letting the ball, goals, and UI independently change scores or launch the next serve. The Unity physics callbacks provide collision and trigger events; they do not prescribe a score target, serve rule, or win condition. Decide those rules for your game.
Rank #4
Use explicit round states
A small state model prevents a goal trigger, reset, and UI button from acting on the same round at once:
- Ready: the ball is stationary and the game can be started.
- Playing: paddles move and the ball is active.
- Point scored: the ball is stopped, the score is updated once, and the next serve is prepared.
- Paused: gameplay is suspended until resumed.
- Match over: the chosen target has been reached and restart is available.
A goal-zone script can report which side was crossed to the controller. The controller should award the point to the opposing player, stop the ball, and choose whether to serve immediately or wait for a start action. Guard the scoring callback so it only runs while the state is Playing; change state before resetting the ball. That ordering prevents a second trigger event during reset from awarding another point.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
On each serve, restore the ball to the center, clear its velocity, reset any paddle positions if that is your chosen rule, and then launch in the selected direction. Keep these operations together so restarting a point cannot leave stale velocity or an outdated match state.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.How do I add a score UI to a Unity Pong game?
This example uses uGUI, the GameObject-based UI system. Add a Canvas, two Text or TextMeshPro score labels, and buttons for Start, Pause/Resume, and Restart. Connect button press events to public methods on the round controller and update the labels when the score changes, rather than polling or rewriting them from unrelated scripts.
Unity’s runtime UI documentation distinguishes UI input setup for the legacy Input Manager and the Input System package. Match the Event System and input module to the project’s active input handling. If you instead choose UI Toolkit, its runtime setup with the new Input System uses an Event System with an Input System UI Input Module; follow the matching legacy-compatible setup when using legacy input (Unity: Runtime UI event system).
Test keyboard or gamepad navigation as well as pointer clicks if those audiences matter. Ensure a selectable control receives focus when the menu appears, that navigation reaches each control, and that the active input backend actually sends UI events. Keep gameplay input and menu input from fighting—for example, disable paddle movement while the game is paused or the match is over.
Quick Recap
What should I test before calling the clone playable?
- Both paddles remain within the court at their movement limits.
- The ball rebounds from both paddles and both horizontal walls.
- Crossing either goal trigger awards one point to the correct player, not multiple points.
- Reset restores the ball’s position and velocity, and any selected paddle-reset behavior.
- Start, pause/resume, and restart controls work with the project’s selected input backend and intended pointer, keyboard, or gamepad interaction.
- The match-over condition prevents further scoring until the player restarts.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




