There is a component that is in nearly all game objects in Unity: Transform. In this tutorial, you will master Unity’s Transform component. To learn how to build 30 virtual reality games in Unity, check out our Unity 3D course!
Select Main Camera from the Hierarchy. To change the camera’s X position in the Scene, you can change the “0” in the X field of the Position property. For instance, change Main Camera’s X position to 2, as in the following screenshot. The camera will move in the Scene.
Another way to change the X position is to click on the “X” beside “Position” and drag your cursor left and right.
Notice that changing the X position moves the camera in one degree of freedom: along the horizontal axis. The horizontal axis is represented as the red arrow extending from the camera in the Scene. You can click on this red arrow to move the camera horizontally.
The gizmo at the top right of the Scene window shows that the red arrow pertains to the X axis.
The Y position represents the vertical axis. Changing the Y position in the Transform component moves the camera up and down.
The X and Y positions allow us to put the camera in a 2D environment. The Z position, which represents the depth axis, creates a 3D environment. Changing the Z position moves the camera forward and back.
Zoom in on Main Camera in the Scene. As evident in the next screenshot, three rectangles are on top of the camera’s icon. You can click on the rectangles to move the camera in different planes. For example, if you click on the green rectangle, you will be able to move the camera in the XZ plane.
The Rotation property in the Transform component works similarly to Position. Changing the X Rotation makes the camera look up and down. Changing the Y Rotation makes the camera look left and right. Changing the Z Position rotates the camera sideways, as though a player were tilting their head to the left and right.
There is another way to change Rotation. In the top left of the Unity window, there are several icons that pertain to available tools. The first tool moves the developer camera. This tool is an alternative to holding the right mouse button.
The second tool, which is pre-selected by default, allows you to move objects. Clicking on the third icon changes the tools around the Main Camera, as evident in the next image. Instead of arrows, there will be a red circle, green circle, and blue circle.
If you click and drag the circles, the camera will rotate. The colors correspond to the different axes: red for X, green for Y, blue for Z. If you click on the sphere between the circles, you can rotate the camera in all three axes.
The third element in the Transform component is Scale, which also has X, Y, and Z values. Scale changes the size of an object. Note that if you change the Scale values for Main Camera, the camera’s size will not change. This is because the camera icon is not rendered in the game. The icon represents the player’s point of view.
Directional Light is also an abstract. The player will not see its icon. Thus Scale will not work on these objects. However, Scale will change the size of a 3D element.
How do you add a 3D element? To learn this and more, check out our Unity 3D course, where we build 30 virtual reality games!