Adding the cherry-throwing capability
In Chapter 7, Implementing our Player Character, we demonstrated the Cucumber Man's throw animation using the E keyboard key. In this section, we will make the necessary changes to instantiate a cherry in the Cucumber Man's right hand when the E keyboard key is pressed and then allow it to be launched. We will check to ensure the Cucumber Man has at least one cherry in his inventory so we know whether a cherry should be instantiated or not. Okay, let's get started.
Creating a spot for the cherry
The following steps demonstrate how to create a spot for the cherry on the Cucumber Man's right hand.
- In the
Hierarchy
panel, expand theCucumberMan
object until you seeCharacter1_RightHand
.
- Right-click
Character1_RightHand
and selectCreate Empty
. - Rename the new GameObject to
cherrySpot
. This will be the spot where we render the cherry.
Your CucumberMan
object's hierarchyshouldlook as follows:
- Using the transform tools, move the
cherrySpot
GameObject so that it is inside...