Collecting cherries from trees
In this section, we will make the necessary adjustments to our game objects and script functionality that enable the collection of cherries from cherry trees. More specifically, we will create the following gameplay:
- Detect collisions of Cucumber Man and cherry trees
- Simulate collection of cherries
- Update inventory and HUD with cherry count
Before we get started, you should open your Unity game project. Alternatively, you can download theStarting-Chapter-10
Unity project available from the publisher's companion site.
Detecting collisions of Cucumber Man and cherry trees
In this section, we will enable and test collisions between the Cucumber Man and cherry trees. Our first step is to ensure the cherry trees in our sandbox area all have the CherryTree
tag. We previously created the tag name, so we only need to apply it to the trees in our sandbox. Here are the steps:
- In the
Hierarchy
panel, select aCherry Tree
that is inside your sandbox area - In the
Inspector
panel...