In this part of the tutorial we learn how combine the different views and also to search and manage objects (e.g., group).
Understanding and becoming familiar with the Interface
As for any major version of Unity, once you open this software for the first time, a project is already loaded and ready to play. This project usually illustrates and brings forward the most interesting features available in the latest version. In Unity 4.x, this project is called AngryBots and includes a very interesting and fun level to play and to discover. All projects delivered in versions1, 2, and 3 of Unity are also available through the Assets Store which is available from Unity by selecting Window | Assets Store from the top menu. At this point in time, although some demo levels have been released for Unity 5.0, an official playable level has not been released yet. This is the reason why we will be using the demo project called AngryBots.
After launching Unity, we can notice that it includes several windows organized in a (default) layout. Each of these windows includes a label (usually at the top-left corner) of the window, and all can be moved around, if necessary by either changing the layout (Window | Layouts | …) or by dragging and dropping the corresponding tab for a window (this will move the view to where you would like it to appear within the window. In the default layout, the following windows appear onscreen (as described in the screenshot below clockwise from the top left corner):
- The hierarchy window (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; for example, we can see in this view if some objects have children or parents.
- 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 them and modify them accordingly using the mouse (e.g., move, scale, etc.)
- The Game view (CTRL+2): this window makes it possible to visualize the scene as it will appear in the game (i.e., through the lenses of the active camera)
- The Inspector view (CTRL+3): this window displays information (i.e., properties) on the object currently selected in the Scene or Hierarchy window.
- The Console window (SHIFT+CTRL+C): this window displays messages either printed from the code by the user (e.g., using specific key words) or by Unity. These include warning or error messages related to your project or code.
- The Project window (CTRL+3): this window includes all the assets available and used for your project; for example: 3D models, sounds, or textures.
Figure 5: 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 (e.g., Scene view) and the active camera present in the scene (e.g., Game view) as illustrated in the next figures.
Note that you can also rearrange the layout to, for example, be able to see both windows Scene and Game views simultaneously. We could drag and drop the game tab beside the Console tab to obtain the layout described on the next figure.
Figure 8: Changing the layout to display both game and scene views
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 out to focus on particular areas or objects, look around (i.e., mouse look) or pan the view to focus on a specific part of the scene. The main modes of navigation are highlighted in the next table; however, we will look into these in more details 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||Shift (in walk mode)|
|Move in four directions (left, right, forward and back)||WASD|
|Float Up and Down||Q,E|
|Look around||Move the Mouse left, right, forth 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 (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 and also look around us by dragging the mouse in the direction we would like to look (i.e., left, right, up and down) and also 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 within. In addition, you can also choose to display the scene along a particular axis (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.
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 width and depth, while y refers to height. In Unity, when the x-axis points to your right, the z-axis is pointing outwards (e.g., towards the screen).
Also note that by clicking on the middle of the gizmo (i.e., white box), we can switch between isometric and perspective views .
In addition to navigation tools, Unity also offers ways to see an object from different perspectives by rotating the view around a particular 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 (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 scene or hierarchy views and pressing the F key), 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 Unity Overview | Unity Basics | Learning the Interface | Scene View) and online using the official documentation link: http://docs.unity3d.com/Documentation/Manual/SceneViewNavigation.htm) When using the documentation, you can also search for particular terms as illustrated on the next figure.
The hierarchy view
As indicated by its name, this view lists and displays the name of all objects included in the scene (by default, 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 the scene can be viewed through the lenses of the camera lenses.
This view offers several advantages when we need to manage all the scene objects quickly and perform organizational changes (e.g., finding objects based on their name, duplicating objects, amending objects’ names, amending the properties of several objects simultaneously, or changing the hierarchy between objects).
For example, on the following figure, we can see that the scene includes four objects: a camera and three cubes.
Figure 11: Creating a hierarchy between objects
We can also notice that all cubes are grouped under a “folder” (in Unity, this is created as an empty object in the scene), which means that:
- All three cubes are children of the object called group of cubes.
- The object group of cubes is the parent of the three cubes.
- 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., cube1, cube2, and cube3).
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
By default, the project view includes two windows, divided vertically (left and right). As illustrated on the next figure, the left window includes a folder called Assets a series of “smart” folders called Favorites. Smart fodders display content based on a criteria or condition. For example, in the following figures, the smart folders listed may include Materials, Models, Prefabs or Scripts. The right window displays the content of the folder selected on the left hand-side.
Figure 12: The project view
In the above figure, the content of the folder Assets is displayed and consists of the current scene labeled Interface. By clicking on any of the smart folders (e.g., All Material, All Models, All Prefabs, or All Scripts) Unity will filter the assets to display only the relevant ones accordingly (e.g., materials, models, prefabs, or scripts). 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.
Figure 13: Searching assets in the project
The search window in the project folder can be used to search assets by their name or types as illustrated in the next figure by clicking on the icon .
Figure 14: Filtering through the assets in the project view
As we can see on Figure 14, 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 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.
This window displays the properties of the object currently selected (i.e., in the scene or hierarchy view) and make it possible to modify and the attributes 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 further on in the book) and a component called Transform. However, it is possible to add components to an object using the button Add Components or through the top menu labelled Component.
Figure 15: The inspector window
You may also notice a tick box 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 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 edited (not played).
The Console view
As seen previously, the console window will display messages from the Unity related to possible errors and warning in your code that may prevent the game from playing, or messages that you can print through your own code.
The Assets Store Window
This window, which is not displayed by default, connects you to the Assets Store, an online repository and market place where you can search for and find assets for your game; some of the assets are free and some other are premium. This window can be accessed through the main menu (Window | Assets Store) or by using the corresponding shortcut (CTRL+9).
Figure 16: The Assets Store view