Welcome to Building Levels in Unity! This book will teach you how to build a complete level from start to finish in a step-by-step fashion. Designed for artists, modelers, animators, game designers, and people with no prior knowledge of game engines, you will find a lot of interesting information about editor functionality, asset import, character tuning, terrain creation, audio, lighting, and much more. Each chapter will focus on a set of topics, to build a solid foundation, and prepare you for more advanced material. By following the examples and using complementary download content, you will have a completely playable and tuned 3D environment.
In this chapter, we will learn the following:
Learn to freely navigate in the Unity editor
Create our first project
Learn about creation and use of built-in primitives
Use and purpose of GameObjects and everything required to deal with them
We will cover all the basics that are necessary for future learning and set up our project that will grow into a fully fleshed level. Let's begin!
I would assume that you've already downloaded Unity and finished the registration process. If you did, then by launching the program, you will be welcomed by the Projects screen where all your future projects will be located. Right now it is empty, so let's add one to it by clicking on the New Project button at the top-right corner.
I'm going to skip the fancy naming and go with My Unity Project this time and leave the default Location. Make sure that you have the 3D option selected, which will default our project to the 3D space and click on the Create Project button to proceed.
We are now going to take a quick look at the Unity editor and all its basic tools and features. You don't have to learn everything by heart at this point, especially if this is your first introduction to this engine; just taking mental notes about what's possible and what tools are available will suffice. We will look into, and study these tools in greater detail later in the book, so don't overwhelm yourself trying to remember everything.
Whenever you first open Unity, you will see a default layout like this:
There are a lot of windows on display. We will be using naming conventions assigned to the windows in the preceding screenshot in all the examples throughout the book, so make sure to reference it whenever you feel lost.
The Scene window allows you to place, select, and edit objects in the level. It's like a sandbox designed for quick and comfortable manipulations of level building. This is where you, as an artist/designer, will spend most of your time working.
Keyboard navigation arrows can be used to simulate walking through the environment. Move forward and backward with the up and down arrow keys, or pan left and right with the left and right arrow keys. Holding the Shift key will significantly increase movement speed. You probably won't use it too often, but it's a nice feature to have nonetheless. In order for hotkeys to have an effect, you need to have the Scene window selected as active, to do so simply left-click inside of it.
Hold the middle mouse button and drag to pan.
Hold Alt + the left mouse button and drag to orbit around the center of the screen.
Hold Alt + right mouse button and drag or scroll the mouse wheel to zoom in and out.
Holding the Shift key will allow you to navigate faster.
You will notice the Hand Tool icon in the Toolbar changing whenever you switch between panning, orbiting, and zooming.
To enter the Flythrough mode, hold the right mouse button, and then use:
The WASD keys to move forward, backward, and sideways
The mouse to look around
The E and Q buttons to go up and down
Holding the Shift key will allow you to fly faster. This navigation method is much more flexible then and similar to using arrow keys; however, it's still a lot more exotic than common.
Located in the upper-right corner of the Scene window, this allows you to quickly change camera orientation by clicking on one of the six cones, or switch between Perspective mode and Isometric mode by clicking on the text or cube in the middle.
Keep in mind that flythrough navigation is specifically designed for the Perspective mode. Gizmo is only available if you are working in the 3D mode.
The scene control bar allows you to choose various options for level viewing.
The drop-down menu (on the left) picks the draw mode for the scene.
Next are three switches that enable/disable 2D mode, lighting, and audio.
The effects button allows you to switch the following effects: skybox, fog, flares, animated materials. Clicking on a button will toggle them simultaneously; clicking on a drop-down menu will allow switching them individually.
The Gizmos menu allows you to control overlay graphics. You can toggle their visibility, control scale, and enable/disable the grid. This menu supports both built-in and custom gizmos created by programmers.
On the right is a search box allowing you to filter items by name or type. The searched objects will remain as is; however, all other objects will go gray scale and become semi-transparent, allowing filtered objects to stand out.
That's the basics of the Scene window. Most of these options are rarely used during development, but they do come in handy the closer you get to the polishing phase.
The buttons are Play, Pause, and Step. The first two are self-explanatory, the third one will play the game for a fraction of time before pausing and waiting for the next click.
Clicking on the Play button will activate the Game window, which will replace the Scene window.
You can switch between Scene and Game windows while testing, or placing them side by side to maximize efficiency, we will discover how to do that in future topics. That allows for a great amount of debugging flexibility; you can move objects, activate scripts, place enemies, all while the game is in progress. However, most changes made during the Play mode will be reset as soon as you stop testing, so be cautious when making those changes. There are useful plugins that you can download from the Unity Asset Store that will allow you to save changes made during the testing, whether to use them or not is completely up to personal preference.
The following menus from the screenshot are explained as follows:
Mute audio: This does exactly what you'd expect it to do.
Stats: This will display rendering statistics, useful for reference when working on optimization.
Gizmos: This menu is the same as the one in the Scene window. These options are very useful during play testing, they allow you to, for example, see triggers and raycasts.
You can create new objects with a Create drop-down menu and quickly focus on them by:
Selecting objects in the Hierarchy window.
Moving the mouse cursor to the Scene window.
Pressing the F key.
This will allocate the camera and focus it on a selected object.
Selecting objects in the Scene or Hierarchy window will allow you to add new Components, edit them and set up materials in the Inspector window. The Public script variables can also be edited without modifying the source code. All the operations regarding importing and some project-related settings will appear in the Inspector window as well.
The Inspector window contains different types of properties such as values, references, arrays, colors, gradients, and curves. Let's take a good look at the first four of them.
Values are the most commonly used property. It can be anything: drop-down menu, checkbox, text field or even a slider. They are no different here in Unity then they are in any other application, just your standard numbers, Booleans, multi choices and strings.
You can assign a reference by dragging and dropping the object into the reference field or using a circle on the right side to open an object picker.
It's important to know that if the required reference type is a Component, you can sometimes reference an object that has that Component attached to it. The reference will be assigned to a first Component of that type. We will talk about the Components later in this chapter.
One thing you need to be aware of when dealing with arrays is how to control their Size. By incrementing the value, you will create more elements that will inherit properties from the last element of the array. However, decrementing the value will delete elements for good, so when you increment the size back, new elements will gain the value of the last element, not the value they used to have before decrementing.
Based on the preceding screenshot, we can safely state that incrementing the Size parameter to
3 will create Element 2 with assigned Reference B reference just like its predecessor Element 1. On the other hand, if we first decrement the Size to
1 and then increment it back to
2, Element 1 reference will be changed from Reference B to Reference A.
Color is your usual RGB value. Clicking on the eyedropper tool will allow you to pick a color from the screen by hovering and left clicking.
Alternatively, you may select the color by opening the Color Picker tool and clicking on the color field. Here you can also create your own libraries of presets for future use.
The latter two property types are not as common and we will look into them when they become relevant.
The default Project window layout is a new feature added with the 4th version of Unity. It's separated into two sections. The left side will show you a folder hierarchy and a list of Favorites (search inquiries). The right side will display previews of objects in the folder as well as the folder's location from the root, at the top.
From here you can select, organize, drag and drop assets into the Scene, Hierarchy, Inspector windows, or create new entities by clicking on the Create drop-down menu in the top-left corner.
Packages are essentially a set of assets compressed into a single file. Packages help transfer data quickly and efficiently between different Unity projects or computers.
To import the package, do the following:
Right-click in the blank space of the Project window, alternatively, select Assets from the top menu.
Navigate to Import Package | Custom Package.
Navigate to the book files saved on your computer.
Select the BuildingLevelsWithUnity.unitypackage file and click on Open.
This will open the window in which you will be able to select files you want, or don't want, to import and then click on import to finalize the process.
Typing in the keywords in a search field will allow you to filter objects that have these keywords in them.
Click on a Type icon located on the right side of the search field to search by type.
Click on a Label icon to search by label.
Click on the Save button to save the search query to the Favorites list on the left.
However, the search in Unity is a lot more powerful than that. You can combine multiple search queries of type and/or label by holding the Ctrl button or simply type them in a search field (
t:typename for type,
l:labelname for labels, searching by keyword works by inputting the keyword).
We will look more into Types and Labels in Chapter 2, Importing and Configuring Props.
Left-click on the entity.
Left-click again in the name area or press the F2 key.
The console will display a list of warnings, errors, and messages as they appear (mostly during play testing), that are useful to pay attention to because Unity can warn you about all sorts of things, not only code related.
There is no need to have the Console window open all the time. The bottom of the screen has an area that will display the latest log in it whenever it appears. Double clicking on it will open the Console window.
This is very useful, since windows like Project and Inspector have a Lock function (Lock sign next to Add Tab) allowing it to keep the current selection and enabling you to work with two objects at the same time.
There are a few layout presets that you may find useful. They are available under the Layout drop-down menu in the top-right corner of the editor or under Window | Layouts of the top menu.
Click on the drop-down menu in the rightmost top corner of the Project window.
Select One Column Layout.
The only real downside of using One Column Layout is a lack of saved search inquiries.
From here on, we will be using the Tall preset layout with Project window set to One column layout (the drop-down menu at the top-right corner of the Project window) to optimize our screen space, but you can choose whichever one you like, this is a preference call.
Revert to default layout by navigating to Layout | Revert Factory Settingsâ¦ in the toolbar, or Window | Layouts | Revert Factory Settingsâ¦ in the top menu.
Recreate the layout presented on the following screenshot:
In order for this to work, you'll need to drag the windows around the editor in search of the invisible Docking Zones.
Cameras are unique GameObjects that serve as our eyes and ears in the game and the editor. By default there are two camerasâthe Editor Camera and a Main Camera. The Editor Camera allows us to see objects in the Scene window and the Main Camera is the one we will be using during play testing. Sure, we can have as many cameras as we want and there are a lot of settings that we can play with, but at this point, it's enough to just be aware of it.
Unity comes with its own set of basic primitives that can be created and edited for quick prototyping or greyblocking. There are Cubes, Spheres, Capsules, Cylinders, Planes, and Quads. They are available under GameObject | 3D Object in the top menu or under the Create menu of a Hierarchy window.
The created object will immediately appear, both in the Scene and inside of the Hierarchy window.
We've covered all the basics that newcomers need to know in order to be comfortable in Unity. Not all, but most of these features, tools, and functions will be used in the future chapters of this book. Whenever you find yourself lost feel free to return to this chapter and review that specific topic. If you need more information, use the official Unity documentation under Help | Unity Manual in the top menu.
In the next chapter, we will start importing assets and configuring them to be used in our level. We will discuss how to export your assets from other apps and how to configure them in Unity, and also set up materials and LODs.