Tutorials¶
Pong¶
Let’s make a simple Pong game! We’ll start by creating a new project with a Pong ball.
- Start Unity
- Create a new project (File / New Project…)
- Add a cube (GameObject / Create Other / Cube)
- Set its position to 0,0,0 in the Inspector window
- Rename it “Ball” in the Hiearchy window
- Select the “Main Camera”, set its position to 0,0,-5, change its background to black, projection to “Orthographic”, and “Size” to 10
- Add a directional light (GameObject / Create Other / Directional Light)
- Save the scene (File / Save Scene) as “Level 1” (It’s always a good idea to save often)
If you press play the “Game” window shows a white square on a black background. But nothing much happens. Here’s how to add a brain to make the ball move.
- Install Brain Builder
- Select the “Ball” game object
- Add a brain component (Component / Brain Builder / Brain) and the Brain Builder window opens
- Drag “Move by x,y,z” from the left panel’s “Position” folder onto the canvas
- Double-click the “x”,”y”,”z” variables and change them to 0,1,0

If you press play, the ball starts moving upwards. Next we will give it a variable speed slot.
- Select the “Ball” again to view its brain in Brain Builder
- Create a new slot and rename it “Speed”
- Change the slot type to “float” and set its initial value to 10
- Drop the “Speed” block from the “Slots” folder onto the “Move by” block’s “1”
This will make the ball move upwards by Speed amount. And you can change its speed by changing the value of Speed in the Inspector. This works even while the game is running!
To make the ball bounce we’ll make it a trigger, add a Rigidbody component, and create walls.
- In the Inspector, check “Is Trigger” on the ball’s “Box Collider” component
- Add a Rigidbody component (Component / Physics / Rigidbody) and uncheck “Use Gravity”
- Add two new cubes named “Wall” and place them at 0,0,0
- Scale the walls along the X axis and place one above and one below the ball by dragging their Y axis
- Open the ball’s brain in Brain Builder
- Drag “Set property to value” from the “Position” folder onto the canvas
- Drag “- value” from the “Math” folder onto the “value” variable
- Drag the “Speed” slot onto both the “property” and “- value” variables
- Drag “OnTriggerEnter(Collider)” from the “Events” folder and snap it to the left of “Set Speed to -Speed”
Press play and the ball should bounce back and forth between the walls. To bounce in both X and Y directions we need two slots for speed. When the ball trigger hits the left/right walls it should change X speed, and when it hits the above/below walls it should change Y speed.
- Add walls to the left and right of the ball
- Rename all the walls so you know which is which
- Rename the slot “Speed” to “Speed Y”
- Add another slot “Speed X” of type float and set its initial value to 10
- In the ball’s brain, drag the “Speed X” block from the “Slots” folder onto the first 0 in “Move by (0,Speed Y,0)”
- Drag another “OnTriggerEnter(Collider)” onto the canvas
- Snap “object1 is object2” from the “Conditions” folder directly below the “OnTriggerEnter(Collider)” block
- Copy the “Collider” variable onto the “object1” variable by holding shift+control while dragging it
- Drag the left wall form the Hierarchy window onto the “object2” variable (look in the Inspector to make sure that a new slot of type “Collider” was created)
- Copy the “Set Speed Y to -Speed Y” block by holding control while dragging it and snap it to the right of the blue block
- Drop the “Speed X” slot onto both copies of “Speed Y”
- Repeat this so that you end up with four rules, one for each wall
The cube bounces between four walls. It’s starting to look like Pong, except there are no paddles yet.
- Make the left wall shorter and rename it “Paddle Player”
- Add a brain to the Paddle
- Use blocks from the “Beginner’s Blocks” and “Position” folders to create these rules:

You can now play by moving the paddle up and down using the arrow keys. But there’s no AI to play against.
- Make the right wall shorter and rename it “Paddle Computer”
- Add a brain to it
- Drag “object’s position” from the “Position” folder onto the canvas
- Drag the “Ball” object from the Hierarchy window onto the canvas (This creates a new slot “Ball” of type GameObject)
- Drag the new “Ball” block onto the “object” variable
- Drag “vector’s y” from the “Math” folder onto the canvas
- Drop the “Ball’s position” block onto the “vector” variable
- Copy this block by ctrl+dragging it
- Drop “my position” from the “Position” folder onto the copied block’s “Ball’s position”
- Use blocks from “Conditions” and “Position” to create these rules:

A fully functional Pong game, except for counting scores.
- In the Ball’s brain, add two new slots “Player score” and “Computer score” of type float
- Add the following rules to the ball’s brain (I used -11 and 11 as the X position of my player and computer paddles):

You can see the score changing in the Inspector. Finally let’s add text objects to display the current scores in the game.
- Create a GUI Text game object (GameObject / Create Other / GUI Text)
- Rename it “Text Player” position it at 0.25,0.75,0
- Change its Text to “0”, Anchor to “middle center”, and Font Size to 40
- Create another GUI Text just like it but named “Text Computer” and position it at 0.75,0.75,0
- Open the ball’s brain and drag “Set GUIText to message” from the “Text” folder onto the canvas
- Drag the “Text Player” game object from the Hierarchy onto the “GUIText” variable
- Drag the “Player score” slot onto the “message” variable
- Snap the resulting “Set Text Player to Player score” block below the rule that updates the player score
- Repeat with “Text Computer” and “Computer score”
We have now completed the Pong project. Happy gaming!