In this tutorial on becoming familiar with Unity, we learn how to manage assets (duplicate, search) as well as how to export a basic scene to a web format that can be played in a browser.
Creating a Simple Staircase
As we have learned how to create objects, there are a few shortcuts that we could experiment with to speed-up the process of creating a scene. To do so, we will go through a simple example of creating a staircase from boxes:
- Select the object labeled greenCube.
- Change its scale settings to (1.5, 0.2, 1).
- Duplicate it several times (e.g., two to three times).
- Move the duplicates along the x and y-axes so that they form a staircase.
- Play the scene to experiment with your staircase.
Managing and searching for assets and objects
As we have seen in the first sections of the book, it is possible to look for particular assets and object in your project and scene using search windows and terms. Let’s use these for our project and start with the hierarchy window:
- If we look at the hierarchy window, you may notice a search window located in its top-right corner. It can be used to look for items in your scene based on their names.
- If we type the word cube for example, it will list all the objects which names include the word cube. You may also notice, as illustrated on the next figure, that other objects do not appear in the scene anymore.
Figure 58: Searching in the hierarchy (cubes)
In a similar way, if we type the word green for example, it will list all the objects which names include the word green. You may also notice, as illustrated on the next figure, that other objects in the scene do not appear anymore in the Scene view.
Figure 59: Searching in the hierarchy (green objects)
Let’s see how we can perform searches in the project window:
- If we click on the project window, you may notice a search window located in its top-right corner.
- After typing the word color, Unity will show all assets with a name that includes this word, in our case, it includes both materials redColor and greenColor.
Figure 60: Searching for assets (color)
- Using the word tile in the search field, Unity will show all assets with a name that includes this word; in our case, it includes both the texture and the material labeled tile.
Figure 61: Searching for assets (tile)
- After typing the word t:material, Unity will show all assets of type material in the project; these include the three materials assets tile, greenColor and redColor that we have created previously.
- Finally, after typing the words t:texture, Unity will show all assets of type texture in the project; these include the texture labeled tile that we have imported in our project and.
Another interesting feature is the ability to group objects. As it is, for example, we have built a staircase; however we would like to move all of its stairs as a whole, rather than each of these individually. It is possible to group all of these by creating a folder, which, in the hierarchy is usually referred as an empty object. Let’s see how:
- Select: Game Object | Create Empty.
- Rename this object container-parent.
- Next, select all the cubes that make-up the stairs (Click + SHIFT)
- Once they are all selected (except from the container-parent object) drag all of them on the object container-parent
- As you do, you will see a black triangle to the left of the object container-parent in the hierarchy and all previous objects listed under this object.
- If we select the object container-parent in the hierarchy and use the Move tool, we can see that by moving this object, all the children are also moving.
Figure 62: Grouping objects
Saving the scene
At this stage, while the project has been saved, we need to save our scene and we can do so as follows:
- Select File | Save Scene As…
- Choose a name for your scene, for example scene2.
- Press Save.
By default the scenes are saved in your project’s folder. You can see all scenes included in your project by looking at the Assets folder and or by searching the project folder using the syntax t:scene (to display all scene files).
Exporting our scene to a web browser
While we have created a very basic scene, it would be great to export it and see how it will look in a browser.
- Select: File | Build Settings: this window helps to specify the settings for the game we would like to export including the scene to be included and the format of the output.
- For now, we will only include the current scene.
- In the section Scene In Build, select and delete all the items present in the list.
- Once the list is clear, click the button Add Current Scene, to add the current scene to the build and select Web Player in the Platform section.
Figure 63: Build settings
- Leave all the other options as default and click on the button labeled Build and Run.
- A new window will appear asking for the name of the build. You can type myFirstGame. This will create a folder and a unity file with the same name within your project folder.
Once the build is complete, you default browser will be launched and the game should appear.
Figure 64: Viewing your game in a browser
>> You can read the full tutorial in one book here (pdf or Kindle) <<