Chapter 8. Interacting with an AR World

Our virtual game world is now being populated with real-world-based places which we want the player to travel to and interact with. For this version of the game, we will let the player visit the places around him and try to sell his cooking monsters. If the place or restaurant likes any of the player's cooks, then it will offer a payment. The player can then accept the payment or move on. However, if the player does accept the payment, the cook will be sold to the restaurant and become its monster chef. A restaurant with a monster chef will not purchase any more cooks until the current chef leaves. A chef will leave after a certain amount of time has expired.

For this chapter, we will focus on completing that interaction of the player exploring the places around them. In order to do this, we will need to construct a new Places scene. This scene will allow the player to sell their monsters to collect new items, such as freeze balls and experience. This will require us to introduce new tables in the database, to handle new inventory items, player experience or level and track the history of a place. Also, we will be introducing a few subtle enhancements along the way. So get ready; this chapter will go over these materials very quickly and will cover the following topics:

  • The Places scene
  • Google Street View as a backdrop
  • Slideshow with Google Places API photos
  • Adding UI interaction for selling
  • The game mechanics of selling
  • Updating the database
  • Connecting the pieces

There will be a few new elements introduced in this chapter, but most of the content added to the game at this point is an extension of concepts covered in several previous chapters. As always, we will continue the project from where we left it from the previous chapter. If you have jumped ahead from a previous chapter, consult the section on downloading the books source code for Chapter 8.

The Places scene

This scene will be another point where we want to mix the content of our alternate game world with the real world. Like the Catch scene, where our AR interaction was a game world on top of the real world, we will do something similar, but this time using a backdrop from Google Street View. We will also use real-world photos of the places within our markers in order to augment our game reality.

Let's get started by creating the new scene and putting the main base elements in place, as follows:

  1. Open up the FoodyGo project from where we left in the previous chapter. If you have jumped ahead, you will need to consult the section on restoring the project from the downloaded source code.
  2. Type Ctrl + N (command + N on Mac) to create a new scene.
  3. Type Ctrl + S (command + S on Mac) to save the scene. Save the scene as Places.
  4. Type Ctrl + Shift + N (command + shift + N on Mac) to create a new empty Game Object. Rename the object PlacesScene and reset the transform to zero.
  5. Drag the Main Camera and Directional Light objects onto the PlacesScene, to make them child objects.
  6. Select the Main Camera object in the Hierarchy window. Then, in the Inspector window, set the Transform PositionY = 2 and Z=-2. We want to raise the camera up and move it forward.
  7. From the menu, select GameObject | UI | Panel. This will add a new Canvas with a child Panel in the Hierarchy window. Select the Canvas object.
  8. Locate the Canvas component in the Inspector window, and set the Render Mode to Screen Space - Camera. Then, drag the Main Camera object from the Hierarchy window into the empty Render Camera slot on the Canvas component.
  9. Select the Panel object in the Hierarchy window. Then, in the Inspector window, change the Image component Color to #FFFFFFFF by clicking on the color slot to open the Color dialog and enter the hex value.
  10. Locate the PlaceMarker prefab in the Assets/FoodyGo/Prefabs folder in the Project window. Select the prefab and type Ctrl + D (command + D on Mac) to duplicate the prefab. Rename the prefab PlacesMarker and drag the new prefab into the Hierarchy window.
  11. Finally, drag the Canvas and PlacesMarker objects onto the PlacesScene object in the Hierarchy window to make them children. Your Game and Hierarchy windows should match the following screenshot:

    The Places scene

    The start of the Places scene

That sets up our base Places scene, and now, we want to add the other AR elements, such as the backdrop, and sign in the next sections.

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

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