Introduction to Unity

Hack A BIT
hackabit
Published in
6 min readOct 4, 2019

In this article, we will first get familiar with the unity editor and then we will create our own game.

So, let’s get started!

When for the first time you create an empty project in unity, you will see an editor gets opened which looks like:

So, here unity editor is divided into four windows:

  1. The Hierarchy Window

The Hierarchy window contains a list of every GameObject in the current Scene. Some of these are direct instances of Asset files (like 3D models), and others are instances of Prefabs, which are custom GameObjects that make up most of your game. When you add or remove GameObjects the Scene (or when your gameplay mechanic adds and removes them), they appear and disappear from the Hierarchy as well.

2. The Project Window

In this view, you can access and manage the assets that belong to your project.

The left panel of the browser shows the folder structure of the project as a hierarchical list. When a folder is selected from the list by clicking, its contents will be shown in the panel to the right. You can click the small triangle to expand or collapse the folder, displaying any nested folders it contains. Hold down Alt while you click to expand or collapse any nested folders recursively.

The individual assets are shown in the right-hand panel as icons that indicate their type (script, material, sub-folder, etc). The icons can be resized using the slider at the bottom of the panel; they will be replaced by a hierarchical list view if the slider is moved to the extreme left. The space to the left of the slider shows the currently selected item, including a full path to the item if a search is being performed.

Above the project structure list is a Favorites section where you can keep frequently used items for easy access. You can drag items from the project structure list to the Favourites.

3. Game and Scene view (Middle Window) :

A) Game View: The Game View is rendered from the Camera(s) in your game. It is representative of your final, published game. You will need to use one or more Cameras to control what the player actually sees when they are playing your game.

B) Scene View: The Scene view is your interactive view of the world you are creating. You will use the Scene View to select and position scenery, characters, cameras, lights, and all other types of Game Object. Being able to select, manipulate and modify objects in the Scene view are some of the first skills you must learn to begin working in Unity.

4. Inspector Window

Use the Inspector to view and edit the properties and settings of almost everything in the Unity Editor, including physical game items such as GameObjects, Assets, and Materials, as well as in-Editor settings and preferences.

When you select a GameObject in either the Hierarchy or Scene view, the Inspector shows the properties of all components and Materials of that GameObject. Use the Inspector to edit the settings of these components and Materials.

The image shows the Inspector with the Main Camera GameObject selected. In addition to the GameObject’s Position, Rotation, and Scale values, all properties of the Main Camera are available to edit.

Scripting

In unity, scripting is done either in C# or javascript language. So here, we’ll go with C#. Unity integrates with Visual studio for executing the scripts.

So, now it’s time to create something!

We will create a small part of a very famous game called “brick breaker” where there is a paddle & a ball and we just have to shoot the bricks hanging in the air with the ball through a paddle.

Here, we will create a paddle, a ball and the paddle will shoot the ball in the air.

LET’S GET STARTED!

Here we will try to create our first game together and that process will be presented through some slides. So, try to go through the slides and keep an eye on all four windows of the editor displayed in the slides to keep a track of how things are working.

Okay so, the first slide shows just the main camera in the hierarchy window which you get by default during creating an empty project.

In 2nd slide, we have added a game Object called background (you can name it anything) and to this game Object, we have given an image (see sprite section in the inspector window).

In the 3rd slide, we have added a game Object called “Play space” further containing 3 child game Objects namely “Right wall”, “Left wall” and “top Wall” which have a property of box collider 2D (see in the inspector window). Collider components define the shape of an object for the purposes of physical collisions. Hence, these three child components act as walls and whenever a ball will collide with these components, it will rebound.

In the 4th slide, we have added another game Object called “Paddle” which signifies a paddle through which shooting and movement of the ball will be controlled. In this Object we have added three properties:

1) Rigidbody 2D -> A Rigidbody 2D component places an object under the control of the physics engine. Here BodyType is set to kinematic not dynamic because while a Dynamic Rigidbody 2D is affected by gravity and forces, a Kinematic Rigidbody 2D isn’t and we don’t want gravity to be applied on the paddle.

2) Box Collider 2D -> An invisible shape that is used to handle physical collisions for an object. Adjust the size of the collider in accordance with the paddle so that it just covers the whole paddle.

3) Script -> In this Script, code for operations like the movement of paddle using cursor of the mouse and shooting the ball is implemented. For reference look below:

In the 5th slide, we have added another game Object called “Ball”. In this Object again we have added three properties:

1) Rigidbody 2D -> Here BodyType is set to dynamic because we want gravity to be applied on the ball.

2) Circle Collider 2D -> Here the shape of the collider is circle as it is of the ball. Adjust the size of the collider in accordance with the ball so that it just covers the whole ball.

3) Script -> In this script, code for operations like the movement of the ball, it’s rebound when the collision with paddle or wall is implemented. For reference look below:

Okay! So, now we are done with the coding and editor part.

Press the play button on the top. You’ll see that the editor screen will go red and the game will get started on a game scene. Press the right mouse button to shoot the ball from the paddle, And

Enjoy your first Unity Game!

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Sanchit Agarwal

Birla Institute Of Technology, Mesra.

--

--