Unity: Game Making
![](https://media0.giphy.com/media/9G5bL5xRRfSqhH6J1X/giphy.gif)
Learning Objectives
To be able to:
- Use and recognise the tools of Unity
- Open and create a new 2D project in Unity
- Use and manipulate shapes in Unity to create Game objects
- Apply basic scripts to objects
The features and tools of Unity
Opening Unity
In your Start Menu, scroll down to 'U' and open the Unity Hub
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10579846/pasted-from-clipboard.png)
Creating a New Project
In your Unity Hub you will need to click on New Project and give it the settings on the next slide.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10579854/pasted-from-clipboard.png)
Creating a New Project
Select a 2D template in the main section of your Hub, then name your Project "Testing Tools"
Once you have done both, select 'Create Project' in the bottom right corner.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10579877/pasted-from-clipboard.png)
Main Screen
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10512807/pasted-from-clipboard.png)
Hierarchy
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10512850/pasted-from-clipboard.png)
Inspector
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10512851/pasted-from-clipboard.png)
Adding Shapes
Tools
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10512985/pasted-from-clipboard.png)
Tools
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10512994/pasted-from-clipboard.png)
Tools
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10512997/pasted-from-clipboard.png)
Tools
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10513000/pasted-from-clipboard.png)
Tools
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10515034/pasted-from-clipboard.png)
Tools
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10515023/pasted-from-clipboard.png)
Tools (Video)
View Points
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10515110/pasted-from-clipboard.png)
Activity
Follow the instructions in the following slides to complete build your first game of Pong
Open a new Project
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521105/Screenshot_2023-06-02_at_11.47.09.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521115/Screenshot_2023-06-02_at_11.49.12.png)
Go to File, New Scene and make sure to press "Basic 2D (Built-in)" -->
(You don't need to save previous work)
Downloading the square
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578480/pasted-from-clipboard.png)
Downloading the square
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578488/pasted-from-clipboard.png)
Downloading the square
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578494/pasted-from-clipboard.png)
Importing the square
Right click in the assets area (not over the folder), Select "Import new asset", select "square.png"
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521123/Screenshot_2023-06-02_at_11.54.25.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521641/Screenshot_2023-06-02_at_14.13.57.png)
Importing the square
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521620/pasted-from-clipboard.png)
Importing the square
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521646/pasted-from-clipboard.png)
Rename the Square
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521655/pasted-from-clipboard.png)
Change the Background
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521680/pasted-from-clipboard.png)
Setting the Boundaries and Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521709/pasted-from-clipboard.png)
Setting the Boundaries and Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521827/pasted-from-clipboard.png)
Setting the Boundaries and Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521833/pasted-from-clipboard.png)
Setting the Boundaries and Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521839/pasted-from-clipboard.png)
Setting the Boundaries and Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10586581/pasted-from-clipboard.png)
Setting the Boundaries and Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521847/Screenshot_2023-06-02_at_15.14.31.png)
You can check the size fits by selecting Game at the top and look to see if your TopWall covers the entire width of the camera.
Setting the Boundaries and Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521859/pasted-from-clipboard.png)
Setting the Boundaries and Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521882/pasted-from-clipboard.png)
Setting the Boundaries and Goals
Our Player1Goal needs to be outside of the camera and cover the height of the camera.
(On the next slide)
Setting the Boundaries and Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10586587/pasted-from-clipboard.png)
Setting the Boundaries and Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521915/pasted-from-clipboard.png)
Setting the Boundaries and Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521919/pasted-from-clipboard.png)
Creating the Players
Now that we have the boarders of the game, we need some players to control.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521924/pasted-from-clipboard.png)
Creating the Players
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521955/pasted-from-clipboard.png)
Creating the Players
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521957/Screenshot_2023-06-02_at_15.42.27.png)
Change the Tag of your Player1 to Player.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521963/Screenshot_2023-06-02_at_15.43.55.png)
Creating the Players
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521975/pasted-from-clipboard.png)
Creating the Players
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10521984/pasted-from-clipboard.png)
Adding Components
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522015/pasted-from-clipboard.png)
Adding Components
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522016/Screenshot_2023-06-02_at_16.05.04.png)
With all objects selected, click on add component in the bottom right and type in Box Collider 2D
Adding Components
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522030/pasted-from-clipboard.png)
Changing this allows the score to change when the ball hits the goal
Adding Components
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522043/pasted-from-clipboard.png)
Adding Components
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522045/pasted-from-clipboard.png)
Final Design Feature
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522087/pasted-from-clipboard.png)
Progress
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522092/pasted-from-clipboard.png)
Neat Labels
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522103/pasted-from-clipboard.png)
It is good practise to keep objects organised, so we will put the boarders into a folder
Neat Labels
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522126/pasted-from-clipboard.png)
Logic
You have now got the base of your game and the next step is to add in some logic so your game works.
![](https://media2.giphy.com/media/TaC6gXdan989My4Eub/giphy.gif)
Player Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578381/pasted-from-clipboard.png)
Player Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578383/pasted-from-clipboard.png)
Player Logic
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Paddle : MonoBehaviour
{
public KeyCode up;
public KeyCode down;
Rigidbody2D rigidBody;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
if(Input.GetKey(up))
{
rigidBody.velocity = new Vector2(0f, 7f);
}
else if(Input.GetKey(down))
{
rigidBody.velocity = new Vector2(0f, -7f);
}
else
{
rigidBody.velocity = new Vector2(0f, 0f);
}
}
}
Copy and replace the code in the window that opens, with this code on the left.
KEEP TRACK OF THE CAPITAL LETTERS!
Press CTRL + S to save your code, otherwise you won't be able to control your players.
Player Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522498/Screenshot_2023-06-02_at_18.44.46.png)
Select both of your players
Player Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522502/pasted-from-clipboard.png)
Player Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578395/pasted-from-clipboard.png)
Player Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578397/pasted-from-clipboard.png)
Test if your Players can Move
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522687/pasted-from-clipboard.png)
Press play again when you are done
Ball Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578256/pasted-from-clipboard.png)
Ball Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578441/pasted-from-clipboard.png)
Ball Logic
Copy and replace the code in the window that opens, with this code on the left.
KEEP TRACK OF THE CAPITAL LETTERS!
Press CTRL + S to save your code, otherwise your ball won't move around.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour
{
Rigidbody2D rigidBody;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody2D>();
Direction();
}
// Update is called once per frame
void Update()
{
}
public void Direction()
{
int direction;
direction = Random.Range(0, 2);
if(direction == 0)
{
rigidBody.velocity = new Vector2(5f, -3f);
}
else
{
rigidBody.velocity = new Vector2(-5f, 3f);
}
}
}
Ball Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522762/pasted-from-clipboard.png)
Ball Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522772/pasted-from-clipboard.png)
Ball Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522774/pasted-from-clipboard.png)
Ball Logic
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522775/pasted-from-clipboard.png)
Freeze the Ball and both Players
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522778/pasted-from-clipboard.png)
Freeze the Ball and both Players
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10522779/pasted-from-clipboard.png)
Game Engine - Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578256/pasted-from-clipboard.png)
Game Engine - Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578263/pasted-from-clipboard.png)
Game Engine - Goals
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Goal : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D collider)
{
collider.GetComponent<Ball>().Direction();
collider.transform.position = new Vector2(0f, 0f);
}
}
Add the function OnTriggerEnter2D() to your script.
Once you have, make sure to press CTRL + S to save your code.
Game Engine - Goals
![](https://s3.amazonaws.com/media-p.slid.es/uploads/1998931/images/10578345/pasted-from-clipboard.png)
You should now have a fully functioning game of Pong!
![](https://media4.giphy.com/media/xTiTnp4JC6WhJPObLO/giphy.gif)
Extension
Experiment with certain aspects of the physics to change the difficulty level of your games. You can try adapting:
- The size of the paddles and ball or
- The Linear Drag of your Players
Unity Lesson 1
By CJackson
Unity Lesson 1
- 161