Building the AR Catch scene

The build up is over; we are finally here: creating the action scene where the players bravely catch the monster. Also, this will be our introduction to incorporating AR into our game. There is lots to do to get this all completed by the end of the chapter, so let's get going. We will start by creating a new Catch scene:

  1. Create a new scene by selecting menu item File | New Scene. Then, select File | Save Scene As... from the menu. In the Save scene dialog, enter the name of Catch and click on the Save button.
  2. From the menu, select GameObject | Create Empty. Rename the new object CatchScene and reset its transform to zero in the Inspector window.
  3. In the Hierarchy window, drag and drop the Main Camera and Directional Light objects on to the CatchScene object, to reparent them.
  4. From the menu, select GameObject | UI | Raw Image. This will create a Canvas object with the Raw Image as a child. Select and rename the RawImage object to Camera_Backdrop in the Inspector window.
  5. With the Camera_Backdrop selected in the Inspector window, set the Anchor Presets to stretch-stretch, by clicking on the Anchors icon to display the menu. Then, hold down the set pivot and set position keys when making the bottom-right corner selection, as follows:

    Building the AR Catch scene

    Setting anchor presets on UI element

  6. In the Hierarchy window, drag and drop the Canvas object onto the CatchScene object.
  7. Select the Canvas object. In the Inspector window, locate the Canvas component. Change the Render Mode to Screen Space - Camera. Then, drag and drop the Main Camera object from the Hierarchy window onto the open Render Camera slot on the Canvas component; refer to the following screenshot for the proper settings:

    Building the AR Catch scene

    Canvas component settings for Screen Space - Camera

    Tip

    The difference between render modes Screen Space - Overlay and Screen Space - Camera is the positioning of the render plane. In the Overlay mode, all the UI elements are rendered in front of everything else in the scene. Whereas, in the Camera mode, a UI plane is created a fixed distance away from the camera. This way, world objects can be rendered in front of the UI elements.

  8. With the Canvas object still selected, change the UI Scale Mode in the Canvas Scaler component to Scale with Screen Size in the Inspector window, as follows:

    Building the AR Catch scene

    Settings for Canvas Scaler component

    Tip

    The Canvas Scaler with Scale with Screen Size will force the camera to maintain the aspect ratio as the screen resolution changes. This is important for us since we don't want the image, which will be the device's camera, to change aspect ratio or distort.

  9. Select and delete the EventSystem object. We won't need it here, and even if we do, Unity will create one for us. Finally, save the scene.

That completes the base Catch scene. Time to move on to the world of AR.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.238.20