Planting Cucumber Patches

We previously identified six areas for our Cucumber Patches. We can follow the same approach in placing Cucumber Patches in our game environment as we used for our Cherry Trees. If we took an auto-planting approach to planting our Cucumber Patches, we would likely end up with a lot more Cucumber Patches than we want. So, we will take a manual approach.

We have prefabs in the Cucumber Patch folder from our early import. Let's do a few things to prepare these prefabs for our use. Follow these steps:

  1. In the Project panel, right-click in the Prefabs folder and select Create | Prefab. Name the prefab CucumberPatch1.
  2. Repeat step 1 and name this second prefab CucumberPatch2.
  3. In the Project panel, drag the Patch1prefab that you imported in the previous section into the Scene view. It doesn't matter where.
  4. In the Hierarchy panel, select the Cucumber Patch you just added to the Scene view.
  5. In the Project panel, ensure that the Prefabs folder is selected.
  6. Drag the Cucumber Patch from the Hierarchy panel to the CucumberPatch1 prefab in the Prefabs folder. 
  7. Delete the Cucumber Patch from the Hierarchy panel.
  8. In the Project panel, drag the Patch2prefab that you imported in the previous section into the Scene view. It doesn't matter where.
  9. In the Hierarchy panel, select the Cucumber Patch you just added to the Scene view.
  10. In the Project panel, ensure that the Prefabs folder is selected.

 

  1. Drag the Cucumber Patch from the Hierarchy view to the CucumberPatch2 prefab in the Prefabs folder. 
  2. Delete the Cucumber Patch from the Hierarchy panel.

We could have just moved the prefabs we imported to the Prefabs folder. Our approach was to duplicate them so that we have the originals available should we need them.

Next, we will prepare the six areas in our game world for the Cucumber Patches. Our goal is to identify the rectangular areas, each with a flat area of ground. 

Using the following reference image and the Unity skills you used to create your terrain, we need to flatten the six areas and record their rectangle boundaries:

To prepare our Cucumber Patch areas, follow these steps:

  1. Use the Paint Height tool to flatten a Cucumber Patch area.
  2. Select GameObject3D ObjectPlane from the top menu.
  3. Position the plane so that it is on the ground, specifically in the flattened area.
  4. In the Inspector view, set the Materials | Element 0 parameter to SpatialMappingOcclusion. This will make the plane transparent.
  5. Once the plane is in place, make note of the transform information.
  6. Repeat steps 1 through 5 for the remaining Cucumber Patches.
  7. Rename the planes so that you have CucumberPatchArea1CucumberPatchArea2CucumberPatchArea3CucumberPatchArea4CucumberPatchArea5, and CucumberPatchArea6.

When you are completed, you should have six defined areas for your Cucumber Patches. For reference, the six areas used in the book's example are shown in the following table:

Plane

Transform

CucumberPatchArea1

X

Y

Z

Position

7373

40.03

1689

Rotation

0

10.082

0

CucumberPatchArea2

X Y Z
Position 1211 40.03 1142
Rotation 0 53.984 0

CucumberPatchArea3

X

Y

Z

Position

1160

40.03

831

Rotation

0

87.876 0

CucumberPatchArea4

X

Y

Z

Position

892

40.03

849

Rotation

0

120.877

0

CucumberPatchArea5

X

Y

Z

Position

1200

40.03

568

Rotation

0

143.801

0

CucumberPatchArea6

X

Y

Z

Position

1184

40.03

330

Rotation

0

103.911

0

 

Our last step is to group the six Cucumber Patches in the Hierarchy panel to help stay organized. As we did with the Cherry Trees, we will right-click inside the Hierarchy panel and select Create Empty. Then rename the GameObject as Cucumber Patch Areas. Lastly, in the Hierarchy panel, select all six Cucumber Patch panes and place them in that GameObject. 

In Chapter 8, Implementing Our Non-Player Characters, we will use the panes to add Cucumber Patches, Cucumbers, and beetles.

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

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