Creating a mini-map

In Chapter 5, Lights, Cameras, and Shadows, you learned about how to use cameras for mini-maps. In this section, we will implement a mini-map for our game. This mini-map will provide a top-down view of our game, centered on the sandbox area you created in Chapter 8Implementing Our Non-Player Character. The player can use this mini-map as a radar to help find Cucumber Beetles in the sandbox.

First, we need to turn the Scene view 2D toggle off. This will put the Scene view back into 3D mode.

Here are the steps for creating a mini-map in our game:

  1. Right-click on an empty area of the Hierarchy panel and select Camera
  2. Rename the camera as Camera_Minimap
  3. Double-click the Camera_Minimap camera in the Hierarchy panel to focus on that object in the Scene view
  4. Change the Transform | Rotation | X value to 90, so it is looking at the ground
  5. In the Scene view, use the transform tools to position the camera so that it covers your sandbox
  6. You can use the Camera Preview to help determine what will be visible during gameplay

The following screenshot shows a Camera Preview that covers the entire sandbox area, bordered with white rectangular walls:

Now that the Camera_MiniMap camera has been added to our scene, we need to ensure it is not treated like our main camera. Here are the steps:

  1. In the Project panel, under Assets, right-click the Textures folder and select Create | Render Texture
  2. Rename the new render texture Render_Texture_Minimap
  3. Select the Camera_Minimap camera in the Hierarchy panel
  4. In the Inspector panel, click the small circle to the right of the Camera | Target Texture property
  5. Select the Render_Texture_Minimap texture you created

The minimap camera is now properly configured. Our next set of steps require us to modify our HUD_Canvas. We will accomplish this with the following steps:

  1. In the Hierarchy panel, drag the Camera_Minimap object so that it is subordinate to the HUD_Canvas
  2. Right-click the HUD_Canvas and select UI | Raw Image
  3. Rename the new raw image UI component as RawImage_Minimap
  4. In the Inspector panel, click the small circle to the right of the Raw Image (Script)Texture property
  5. Select the Render_Texture_Minimap texture you created
  6. Toggle the Scene view 2D toggle on
  7. Double-click the HUD_Canvas in the Hierarchy panel, then zoom in so you can see a close-up of the canvas
  8. Relocate the RawImage_Minimap so that it is in the lower-right-hand corner of the canvas
  9. Change the Rect Transform | Scale to 2 for X, Y, and Z

You are now ready to test your game in game mode. You should see the mini-map in the bottom-right-hand corner of the screen, illustrated in the following screenshot:

You can use this mini-map as a great starting point as you work to refine how it looks in the game. Some options for refinement include giving the mini-map more contrast with the game world and showing red dots for Cucumber Beetles instead of only showing the entire terrain.

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

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