Frame options objects

Next, we add the menu selection options as child objects of the FrameMenu and make them clickable.

Earlier in the chapter, you may have installed the PhotoFrames assets with the chapter's Unity package. If not, you can go ahead and create a couple more, the same way that you created the first one back in the recipe Create default picture in the Setting up the project and scene section. For example, you may create a cube, scale it to (1.2, 1.2, 0.02), with the Position set to (0, 0, 0.02), and create and assign it a colored Material. Save them as prefabs named Frame 1, Frame 2, and Frame 3.

Because the menu options are clickable, receiving input events, they must have colliders. We'll handle this by parenting the actual frame prefabs with the menu item objects named Frame A, Frame B, and Frame C.

Follow these steps to create the menu game objects:

  1. With FrameMenu selected in the Hierarchy, click Create Empty, and name it Frame A.
  2. From the Project Assets/PhotoFrames/Prefabs/ folder, drag the Frame 1 prefab as a child of Frame A.
  3. Make sure Frame A is still selected and set its Scale to (0.25, 0.25, 0.25).
  4. Set its Position X to −0.35.
  5. Add the ClickableObject component to it.

Repeat the preceding steps for Frame B (Frame 2) and Frame C (Frame 3). Position them horizontally at X 0.0 and 0.35, respectively.

Now populate the FrameMenu component with the frame objects we just created:

  1. Select FrameMenu in the Hierarchy.
  2. Enter 3 for Clickable Objects Size.
  3. Drag each of its child Frame objects into the corresponding Clickable Object Element slot in the FrameMenu component, as shown here:

We now have a FrameMenu, with clickable child frames for the user to pick. The scene now looks like this:

Let's try it out.

  1. Save your files and the current scene.
  2. Press Play.

You should see the Frames menu. Select one of the frames and it will replace the current frame in the picture.

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

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