Becoming Familiar with Unity: Part 4

b2

In this part of the tutorial we learn add and modify new objects.

Creating a new project and a new scene

Now that we have covered the main features for the interface, we will create a new project with a simple game where the player has to jump on boxes without falling. It will be using simple built-in objects and standard assets (i.e., First-Person Controller) as well as textures and colors for some of these objects.

After completing this section you will be able to:

  • Add basic objects to your scene.
  • Apply basic texturing and coloring to objects.
  • Transform objects (i.e., move, scale and rotate).
  • Add a character controller to the scene to be able to navigate.
  • Add and configure lights.
  • Group objects and apply attributes to several objects at a time.

First, let’s create a new scene:

  • Select File | New Scene to open a new scene.
  • This should open a new scene.
  • At this stage, we have a blank canvas where we can start to add objects and build our game.

 new_scene_full_view

Figure 25: Opening a new scene

Adding and combining simple built-in objects to your scene

As we will see later on, we can create our game environment using a wide range of primitive shapes (e.g., cylinders, spheres, boxes, etc.), lights (e.g., directional lights or point lights), cameras and other built-in assets (e.g., character controllers). Once these objects have been added to the current scene, Unity makes it possible to modify their attributes.

As we open the new scene, you will see that, by default, the scene includes a camera that is called Main Camera. This will be the case for any new scene and we will be able to either delete this camera or modify its properties (e.g., location or orientation) at a later stage.

If you click on this camera in the hierarchy view, you should be able to see a small window labeled Camera Preview in the bottom-right corner of the scene view. This preview window represents the scene viewed through the lenses of the camera.

 new_scene_camera

Figure 26: Default camera for a new scene

This is how your game will be viewed. At present we can only see a blue screen within this preview as no objects or lights have been added yet to the scene. We can also see that the inspector window, that is located to the right of the screen, displays the attributes of this camera. Amongst other things, we see that it is located at the position (x=0, y=1, z=-10) and that it has not been rotated yet. Finally, if we look at the scene view, we can see three arrows from the object, one red (along the x axis), one green (along the y-axis) and the last one blue (along the z-axis).

If you click on the Game tab, you will also see a blue screen (as displayed in the camera preview).

 new-scene_game_view

Figure 27: Blank game view for a new scene

First let’s create a cube that will serve as the ground:

  • Select: GameObject | 3D Object | Cube, from the top menu.
  • This will create a box that will be, by default located at (0,0,0) with a size of 1. This means that the height, depth, and width of this object are equal 1.
  • Rename the cube myCube: to rename the cube we can either (1) select it in the hierarchy window and then press CTRL+ENTER simultaneously or (2) select it in the hierarchy window and left-click once on it, or (3) right-click on the object in the hierarchy window and select Rename from the contextual menu.

Once you have renamed the cube, we can change some of its properties and see how it affects its appearance. For example:

  • In the inspector window, change the x, y, and z scale properties to 2 and see how its size has been affected.
  • Change its y rotation attributes to 45 (i.e., a rotation around the y-axis expressed in degrees), and see how its orientation has changed. Note that for any of these parameters, you can either change the value of the corresponding text fields, or click on one of the labels (e.g., x,y or z) and drag and drop the mouse: this will either increase or decrease the value in the corresponding field. It usually is an easier way to amend an object’s attributes.

Once you are comfortable with modifying the transform properties of the cube using the inspector, let’s look at other interesting ways to look at the objects and scene to modify their attributes.

You will notice a tool bar located at the top left corner of the window, as illustrated on the next figure.

 tool_bar

Figure 28: Toolbar

This toolbar includes five distinct buttons that are shortcuts to (1) modify the view mode (e.g., pan, or rotate the view), (2) move the object currently selected, (3) rotate the object currently selected, (4) scale the object currently selected, and (5) both move and scale the object currently selected. These five buttons can also be accessed using the key shortcuts Q, W, E, R and T.

Lets’ experiment with the panning tool:

  • Select the panning tool from the tool bar (1st icon from the left or press the key Q).
  • You should see that the mouse pointer turns into a hand.
  • Drag and drop the mouse in the screen view: you should see that you effectively pan the view.

Now, lets’ experiment with the Move tool:

  • Select the Move tool from the toolbar or use the corresponding shortcut (W)
  • You should now see three arrows from the cube. These arrows are handles that you can drag and drop to move the selected object in a particular direction (e.g., along the x-, y- and z-axes).
  • As we successively drag the blue, red and green handles, observe how these move your object along the corresponding axes.

Before we look at the three last modes, let’s look at a useful widget called a gizmo. This widget, as illustrated on the next figure, is located in the top-right corner of the scene view and makes it possible to view the scene from several axes and perspectives.

 gizmo

Figure 29: using the gizmo

Using this gizmo, and by clicking on its x, y, or z arms, we can see the scene from the corresponding axis. Let’s experiment with it:

  • We can successively click on the x, y, and z arm of the gizmo, and see how the view changes.
  • Note that by pressing in the middle of the gizmo, we can reset the view to its initial state (x-axis pointing to the right, y-axis pointing upwards, and z-axis pointing outwards).
  • To readjust the view, we can also use ALT key and drag and drop the mouse, so that we can rotate around the object accordingly.

After this short distraction, let’s come back to our top-left tool bar and experiment with the three remaining buttons.

Now, lets’ experiment with the Rotation tool:

  • Select the Rotation tool from the toolbar (third icon) or use the corresponding shortcut (E).

You should now see a combination of green, red, and blue circles around the object. These are handles that you can drag and drop to rotate the selected object around a particular axis (e.g., around the x-, y- and z-axes).

 rotate_object

Figure 30: Rotating an object

The color of the handle indicates the axis around which the object will be rotated. For example, by dragging and dropping the green handle, we can rotate the object around the y-axis. The same applies to the blue (z-axis) and red (x-axis) handles.

As we drag these handles, we can see that the values for the corresponding rotation in the inspector change also.

 rotate_object_around_y

Figure 31: Rotating an object around the y-axis

Now, lets’ experiment with the Scale tool:

  • Select the Scale tool from the toolbar (fourth icon from the left) or use the corresponding shortcut (R).
  • You should now see a combination of green, red, and blue lines and handles around the object. These are handles that you can drag and drop to scale the selected object along a particular axis (e.g., along the x-, y- and z-axes).

 scale_object

Figure 32: Scaling an object

The color of the handle indicates the axis along which the object will be rotated. For example, by dragging and dropping the green handle, we can scale the object around the y-axis. The same applies to the blue (z-axis) and red (x-axis) handles. Also note that by dragging the middle white square, the transformation will be uniform. In other words, the amount of scaling will be the same on all three axes (x-, y, and z-axes).

At this stage, we have performed several transformations on the new cube, and we may want to reset its attributes so that it is the same as when it was initially created. We can do so by using the cogwheel located in the top-right corner of the transform attributes of the cube, as described on the next figure.

 reset_component

Figure 33: Resetting the attributes of an object

The last item on the tool bar is the Rect tool. It combines the Move and Scale tools. Once you have selected this tool, you can move the object by dragging and dropping the mouse, or modify the object’s width, height, and depth by dragging and dropping corresponding handles.

For more information and tips on how to use Unity’s interface, you can visit: http://docs.unity3d.com/Manual/LearningtheInterface.html

Related Articles: