Exercise - Position game objects and set visibility

Completed

Now let's learn how to create parent objects, add prefabs to the scene, and use the Transform component to place them in particular positions.

Import the tutorial assets

To get started, first download the following Unity custom package: MRTK.HoloLens2.Unity.Tutorials.Assets.GettingStarted.3.0.0.unitypackage

  1. In the Unity menu, select Assets > Import Package > Custom Package....

    Screenshot that shows how to import a custom package.

  2. In Import package, select the MRTK.HoloLens2.Unity.Tutorials.Assets.GettingStarted.3.0.0 unitypackage that you downloaded, and then select Open.

    Screenshot that shows how to import the tutorial package.

  3. In Import Unity Package, select All to ensure that all the assets will be imported. Then select Import.

    Screenshot that shows how to select all the assets.

Create the parent object

  1. In the Hierarchy window, right-click on an empty spot, and select Create Empty to add an empty object to your scene.

    Screenshot that shows how to create and add an empty object to your scene.

  2. Right-click on the newly created object, select Rename, and change the name to RoverExplorer.

    Screenshot that shows how to rename the object.

  3. With the RoverExplorer object still selected, in the Inspector window, configure the Transform component as follows:

    • Position: X = 0, Y = 0.9, Z = 2
    • Rotation: X = 0, Y = 0, Z = 0
    • Scale: X = 1, Y = 1, Z = 1

    Screenshot that shows the RoverExplorer object selected and positioned.

Add the tutorial prefabs

  1. In the Project window, go to the Assets > MRTK.Tutorials.GettingStarted > Prefabs folder.

    Screenshot of the Project window with the Prefabs folder selected.

  2. From the Project window, drag the Table prefab onto the RoverExplorer object, to make it a child of that object. Then, in the Inspector window, configure the table's Transform component as follows:

    • Position: X = 0, Y = -0.005, Z = 0
    • Rotation: X = 0, Y = 0, Z = 0
    • Scale: X = 1.2, Y = 0.01, Z = 1.2

    Screenshot of the newly added Table prefab selected and positioned.

  3. From the Project pane, drag the RoverAssembly prefab onto the RoverExplorer object, to make it a child of that object. Then, in Inspector, configure the Transform component as follows:

    • Position: X = -0.1, Y = 0, Z = 0
    • Rotation: X = 0, Y = -135, Z = 0
    • Scale: X = 1, Y = 1, Z = 1

    Screenshot of the newly added RoverAssembly prefab selected and positioned.