Adding cucumbers to our terrain

Cucumbers will be used in our game to give the beetles something to search for and to eat. We will place several cucumbers in the sandbox area and, in Chapter 10, Scripting Our Points System, keep track of how many there are during gameplay. In this section, we will prepare the cucumbers for our use and populate them in our game.

You previously downloaded the necessary assets for the cucumber. As you can see in the following screenshot, Cucumber is accessible in the Assets/Cucumber folder. You will note that when we select Cucumber, the bottom of the Project panel identifies the Cucumber file as a .fbx file:

The .fbx file was exported from the 3D modeling software so we can use it in our game. When that asset is selected, the inspector view shows Import Settings. We want access to the transform, mesh renderer, and other components, so we will turn it into a prefab and make some changes. Here are some initial steps:

  1. Drag the Cucumber.fbx file from Assets | Cucumber to the Hierarchy panel
  2. With the Cucumber selected in the Hierarchy panel, drag it to the Assets/Prefabs folder in the Project panel
  3. Delete the Cucumber from the Hierarchy panel
  4. In the Project panel, select Assets | Prefabs | Cucumber

When we select the Cucumber file we just moved from the Hierarchy panel to the Prefabs folder, the bottom of the Project panel, shown in the following screenshot, identifies Cucumber as a prefab:

Now, when we look in the Inspector panel, we have access to the components we need to further prepare the cucumber for use in our game. Let's make a few changes to the prefab:

  1. In the Inspector panel, select Tag | Add Tag.
  2. In the Tags & Layers interface, click the plus icon to the right of the view. As shown in the following screenshot, beneath the plus icon is the CherryTree tag and to the right:
  1. Enter the name Cucumber.
  2. Click the Save button.
  3. Select the Assets | Prefabs | Cucumber prefab in the Project panel.
  4. In the Inspector panel, select Tag | Cucumber

Now that our cucumber prefab has a tag, all copies of it will have that same tag. This tag will facilitate the following for us regarding gameplay:

  • Easily count how many cucumbers are left in the game
  • Identify when a beetle has found a cucumber

We have one more modification to make for our cucumber prefab—add a collider:

  1. Select the Assets | Prefabs | Cucumber prefab in the Project panel
  2. In the Inspector panel, click the Add Component button
  3. Select Physics | Box Collider

Next, we can add cucumbers to our sandbox area. First, let's take the same approach as we did for the cucumber patches in regards to organization:

  1. Right-click the Sandbox in the Hierarchy panel and select Create Empty.
  2. Rename the new GameObject to cucumbers.

 

  1. Drag several Cucumber prefabs onto the scene, in your sandbox. You can also drag a single prefab into the Scene view and make copies of it using the shortcut Ctrl + D, which will duplicate all currently selected objects.
  2. Using the transform tools, rotate, resize, and relocate the cucumbers.
  3. Ensure you have at least 10 cucumbers in your sandbox area.
  4. In the Hierarchy panel, move all the newly created cucumbers to the cucumbers game object under Sandbox. This is merely to keep the Hierarchy panel organized.

Once you have your cucumbers dispersed throughout the sandbox area of your game world, you are ready to start scripting the Cucumber Beetles. We will take care of this in the next section.

This is a good time to save your scene and your project.
..................Content has been hidden....................

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