Unity (Foundations) Part 1


Installing Unity and Becoming Familiar with the Interface

This chapter helps you to progressively become familiar with Unity by explaining and illustrating how to install this software, and how the different views and core features can be employed. You will also learn to create your first project and scene, using predefined objects such as boxes. After learning the features of the different views available in Unity, you will learn how to navigate through a scene (to look at objects), before creating your very first game environment with built-in objects and applying colors and textures.

After completing this section, you should be able to:

  • Be more comfortable with Unity’s interface.
  • Understand the role and location of the different views in Unity.
  • Understand the role of colliders.
  • Add and configure cameras and lights.
  • Know and use shortcuts to manipulate objects (e.g., move, scale, resize, duplicate, or delete) and move the view accordingly (e.g., pan or rotate).
  • Use the Inspector view.
  • Create and apply colors and textures to objects.
  • Create and combine simple built-in shapes.
  • Know how to search for and organize assets in your game efficiently.
  • Navigate through your scene and see it from both first- and third-person views.

If you need more help or information on the topics covered in this section, you can gain access to a FREE video training based on this book (i.e., 2-hour training) by using the following link: http://learntocreategames.com/. This training will show you exactly all of the steps covered in this book and may appeal to those who are more visual learners.

Downloading Unity Hub

Now that you have had an overview of Unity and game engines, it is time for us to start using Unity. However, before you can install and use Unity, you will need to download and install Unity Hub using the following steps:

  1. Open the following link: https://www.unity3d.com/download. This will help you to check that your computer complies with Unity’s requirements.
  2. Once you have checked the requirements, we can download Unity Hub from the same.
  3. Please follow the installation instructions.

Installing Unity

As mentioned in the previous section, you will need to install Unity Hub before you can install a version of Unity.

  1. Once Unity Hub is installed, you can install a new version of Unity by going to the section called Installs and then selecting the option to Install Editor.

A screenshot of a computer

Description automatically generated

Figure 2‑1: Installing Unity

  1. You can then select the version of Unity that you need (for example, Unity 2019.2) as per the next figure.

A screenshot of a computer

Description automatically generated with medium confidence

Figure 2‑2: Adding a new version of Unity

  1. You can press the “Next” button.
  2. You will be asked whether you want to install additional modules. For the time being you can leave all the options as default (i.e., no additional modules).

A screenshot of a computer

Description automatically generated with medium confidence

Figure 2‑3: Selecting additional modules

  1. Click on the button labelled “Continue” and follow the instructions.
  2. Once the new version of Unity is installed, it will be listed in Unity Hub in the section called Installs.

A screenshot of a computer

Description automatically generated with medium confidence

Figure 2‑4: Checking that the new version has been installed

Launching Unity

Once you have successfully installed Unity and its components, we can now launch it through Unity Hub. Upon the first time you open Unity, you may need to provide your email address, so that you can receive regular updates from the Unity team. This should be really useful to keep up to date with major announcements for this software. You may also be asked whether you would like to activate the Pro version. However, for the purpose of this tutorial, you only need to use the free version (i.e., personal edition).

After having provided your email details as well as choosing the free version of the software, we can start to enjoy Unity.

Before you create your first scene, you will need to download the startup project from the following url:

http://www.learntocreategames.com/book_downloads/book1/StartupProject.zip

This startup project includes lots of assets that you will be able to use in your projects, including cars, planes, animated characters, and textures to design your Island.

Once the download is complete:

  • Please take note of where you have saved the zip file.
  • Unzip the file.
  • You should obtain a folder called StartupProject.
  • You can now open this project through UnityHub.
  • In Unity Hub please select the section called Projects from the left menu.

Graphical user interface, application

Description automatically generated

Figure 2‑5: Selecting the Project tab

  • Click on the button labelled “Open” so that you can open the Startup project that you have just downloaded.

A picture containing icon

Description automatically generated

  • In the new window, please navigate to the folder where the startup project was saved, select it, and press Open.

Graphical user interface, application

Description automatically generated

When Unity starts-up, a window labeled Unity Editor Update Check appears. This window, illustrated below, is there to check whether you have the latest version of Unity and to let you know of any recent updates available. If an update is necessary, you can install it. If you would prefer not to see this message displayed every time you start Unity, you can uncheck the corresponding box labeled Check for Updates accordingly.

Text

Description automatically generated

Figure 2‑6: Automatically checking for Unity updates

Unity provides links to official forums and documentation from the main (i.e., top) menu: Help | Unity Forums or Help | Unity Manual.

Understanding and becoming familiar with the interface

After launching Unity, you will notice that it includes several windows organized in a (default) layout. Each of these windows includes a label in their top-left corner. These windows can be moved around and rearranged, if necessary, by either changing the layout (using the menu Window | Layouts | …) or by dragging and dropping the corresponding tab for a window to a different location. This will move the view (or window) to where you would like it to appear within the window. In the default layout, the following views appear onscreen (as described in the next screenshot, clockwise from the top left corner):

  1. The Hierarchy window (the corresponding shortcut is CTRL+4): this window or view lists all the objects currently present in your scene. These could include, for example, basic shapes, 3D characters, or terrains. This view also makes it possible to identify a hierarchy between objects, and to identify, for example, whether an object has children or parents (we will explore this concept later).

If you are using Mac OS, then CTRL can be replaced by CMD.

  1. The Scene view (CTRL+1): this window displays the content of a scene (or the item listed in the Hierarchy view) so that you can visualize and modify them accordingly (e.g., move, scale, etc.) using the mouse.
  2. The Game view (CTRL+2): this window makes it possible to visualize the scene as it will appear in the game (that is, through the lens of the active camera).
  3. The Inspector view (CTRL+3): this window displays information (i.e., the properties) on the object currently selected.
  4. The Console window (SHIFT+CTRL+C): this window displays messages that are printed from the code by the user, or warnings and error messages related to your project or code displayed by Unity.
  5. The Project window (CTRL+5): this window includes all the assets available and used for your project, such as 3D models, sounds, or textures.

A screenshot of a computer

Description automatically generated

Figure 2‑7: Main windows and views in Unity

The scene view

We will use this view to create and visualize the scene for our game. When you create a project, you can include several scenes within. A scene is comparable to a level, and scenes that are included in the same project can share similar resources, so that assets are imported once and shared across (or used in) all scenes. The Scene and Game views are displayed in the same window, and both are represented by a corresponding tab. By default, the Scene view is active. However, it is possible to switch to the Game view by clicking on the tab labeled Game. For example, if we click successively on the Game and Scene tabs, we can see the view from both the perspectives of your eyes (i.e., the Scene view) and the active camera present in the scene (i.e., the Game view) as illustrated in the next figures.

Figure 2‑8: The Scene view

A screenshot of a blue screen

Description automatically generated

Figure 2‑9: The Game view

Note that you can also rearrange the layout to be able to, for example, see both the Scene and Game views simultaneously. We could, for example, drag and drop the Game tab beside the Console tab to obtain the layout described on the next figure.

Figure 2‑10: Changing the layout to display both Game and Scene views

In the previous figure, the Game tab that is usually to the right of the tab called Scene has been dragged to the right of the tab called Project. This way, you can see both the Scene view and the Game view simultaneously.

Discovering and navigating through the scene

So that you can navigate easily in the current scene, several shortcuts and navigation modes are available. These make it possible to navigate through your scene just as you would in a First-Person Shooter or to literally “fly” through your scene. You can also zoom-in and zoom-out to focus on specific areas or objects, look around (i.e., using mouse look) or pan the view to focus on a specific part of the scene. The main modes of navigation are provided in the next table. However, we will look into these in more detail in the next section as we will be experimenting with them to explore (and modify) an existing scene.

Table 1: Navigation shortcuts

Navigation

Key or Mouse Combination

Activate Fly Mode

Keep MRB (Mouse Right Button) pressed.

Accelerate

Press Shift (in walk mode).

Move in four directions (left, right, forward and back)

Press W, A, S, or D (in fly mode).

Float Up and Down

Press Q or E (in fly mode).

Look around

Press ALT and drag the mouse left, right, forward or back.

Zoom in/out

Move the mouse wheel.

Pan the view

Press Q (to activate the hand tool) then drag and drop the mouse.

For example:

  • In the default navigation mode, you can “walk” through the scene using the arrow keys (i.e., up, down, left and right).
  • In the “flight” mode, which can be activated by pressing and holding the Mouse Right Button (MRB), we can navigate using the W, A, S and D keys.
  • In the “flight mode”, we can also look around us by dragging the mouse or float up and down using the keys Q and E.

As you can see, both modes are very useful to navigate through your scene and to visualize all its elements. In addition, you can also choose to display the scene along a particular axis (i.e., x, y, or z) using the gizmo that is displayed in the top-right corner of the Scene view as described on the next figure.

A screenshot of a computer

Description automatically generated

Figure 2‑11: Gizmo

The gizmo available in the Scene view includes three axes that are color-coded: x (in red), y (in green) and z (in blue). By clicking on any of these axes (or corresponding letters), the scene will be seen accordingly (i.e., through the x-, y-, or z-axis).

If you are not familiar with 3D axes: x, and z usually refer to the width and depth, while y refers to the height. By default, in Unity, the z-axis is pointing towards the screen if the x-axis is pointing to the right and the y-axis is pointing upwards. This is often referred as a left-handed coordinate system.

Also note that by clicking on the middle of the gizmo (white box), we can switch between isometric and perspective views.

In addition to the navigation tools, Unity also offers ways to focus on a particular object by rotating around a specific point (i.e., by pressing the ALT key and dragging the mouse to the left, right, up or down), or double-clicking on an object (i.e., in the Scene or Hierarchy view), so that the camera in the Scene view is focused on this object (this can also be achieved by selecting the object in either the Scene or Hierarchy view and by then pressing SHIFT+ F), or by zooming-in and out (i.e., scrolling the mouse wheel forward or back).

While the shortcuts and keys described in this section should get you started with Unity and make it possible for you to navigate through your scene easily, there are, obviously, many more shortcuts that you could use, but that will not be presented in this book. Instead, you may look for and find these in the official documentation that is available both offline (using the top menu: Help | Unity Manual then select the sections Working in Unity | The Main Windows | The Scene View | Scene View navigation) and online (http://docs.unity3d.com/Documentation/Manual/SceneViewNavigation.html). When using the documentation, you can also search for particular words as illustrated on the next figure.

A screenshot of a computer

Description automatically generated

Figure 2‑12: Using Unity’s manual

The hierarchy view

As indicated by its name, this view lists and displays the name of all objects included in the scene (in alphabetical order, by default) along with the type of relationship or hierarchy between them. You may notice that before you add any object to the scene, a camera is already present in the scene so that it can be viewed in the Game view through its lenses.

This view offers several advantages when we need to manage all the objects present in the scene quickly and to perform organizational changes. For example, we could use this view to find objects based on their name, to duplicate objects, to amend the name of objects, to amend the properties of several objects simultaneously, or to change the hierarchy between objects.

For example, on the following figure, we can see that the scene includes seven objects including a camera, a directional light, four cubes, and an object called group_of_cubes.

Figure 2‑13: Creating a hierarchy between objects

We can also notice that all cubes are grouped under a “folder” (in Unity, this can be created as an empty object in the scene), which means that:

  1. All four cubes are children of the object called group_of_cubes.
  2. The object group_of_cubes is the parent of the four cubes.
  3. If a transformation (i.e., scale or rotate) is applied to the parent (e.g., group of cubes) it will also be applied to the children (i.e., Cube, Cube(1), Cube(2), Cube(3) and Cube(4)).

To change the hierarchy of the scene and make some objects children of a particular object, we only need to drag these objects atop the parent object.

The project view

This view includes and displays all the assets employed in your project (and across scenes), including: audio files, textures, scripts (e.g., scripts written in C#), materials, 3D models, scenes, or packages (i.e., zipped resources for Unity). All these assets, once present in the Project view, can be shared across scenes.

In other words, if we create a project and then a scene, and import assets for our game, these assets will be available from any other scene within the same project.

As for the Hierarchy view, built-in folders and search capabilities are included to ease the management of all your assets.

By default, the Project view includes two windows divided vertically (left and right columns). As illustrated on the next figure, the left window includes a folder called assets and a series of “smart” folders (i.e., the content of these folders varies dynamically) called Favorites. The right window displays the content of the folder selected on the left-hand side.

Graphical user interface

Description automatically generated

Figure 2‑14: The project view

By clicking on any of the smart folders (e.g., All Materials, All Models, or All Prefabs) Unity will filter the assets to display only the relevant ones accordingly (e.g., materials, models, or prefabs). This can speed-up the process of accessing specific assets and can be done, as for many of the functionalities present in Unity, in different ways. For example, you may notice a search window to the left of the Project view as illustrated in the next figure.

Background pattern

Description automatically generated with medium confidence

Figure 2‑15: Searching for assets in the project

The search window in the Project folder can be used to search assets by their name or by their type, as illustrated in the next figure, by clicking on this icon .

Graphical user interface

Description automatically generated

Figure 2‑16: Filtering through the assets in the project view

As we can see on the previous figure, we have the option to select the type of assets that we are looking for (e.g., Texture, Prefab, or Script). Note that this option can also be specified by typing t: followed by the type that we are looking for in the search window. For example, by typing t:material in the search window, Unity will only display assets of type Material.

The inspector

This window displays the properties of the object currently selected (i.e., the object selected in the Scene or the Hierarchy view) and it makes it possible to modify the attributes of an object accordingly. All properties are categorized in Components.

By default, all objects present in the scene have a name, a default layer (we will look at this aspect later) and a component called Transform. However, it is possible to add components to an object using the button Add Component (see next figure) or the menu called Component.

A screenshot of a computer

Description automatically generated with low confidence

Figure 2‑17: The Inspector window

You may also notice a tick box, in the Inspector window, to the left of the name of the object, that can be used to temporarily deactivate (and consequently reactivate) the object. This can be useful when you would like to temporarily remove an object from the scene without having to recreate it.

As we will see later, there are many types of components that can be added to an object to enhance it, including physics properties (to enhance how an object will behave realistically following the laws of physics), rendering (to enhance its appearance), or collision (to refine how it will detect collisions with other objects). For example, the default component Transform includes the position, rotation, and scale attributes of the object selected.

The attributes tag, layer, and static, while important, will be covered in later sections.

As we will see later, a scene can be edited and played. However, if we try to modify the attributes of an object while the game is playing, these will not be saved. In other words, for modifications to be saved in the scene, they have to be made while the game is stopped (i.e., not played).

The console view

As seen previously, the console window will display messages from Unity, related to possible errors and warnings in your code that may prevent the game from playing, or messages that you can print through your own code (e.g., for debugging purposes).

Graphical user interface, text, application

Description automatically generated

The asset store window

This window, which is not displayed by default, connects you to the Asset Store, an online repository and market place where you can search for and find free or premium assets for your game. This window can be accessed through the main menu (i.e., Window | Asset Store) or by using the corresponding shortcut (CTRL+9) and will be displayed in your default browser.

Graphical user interface, website

Description automatically generated

Figure 2‑18: The Asset Store view

Level roundup

Summary

In this chapter, we have become familiar with the different views and windows available in Unity. We also looked at how to navigate through scenes and how to change the layout of our working environment. In the next chapter, we will harness these skills to be able to create and navigate through our own 3D environment.