In this section, we will configure the Cucumber Man prefab so that it supports audio when the Cucumber Beetles eat, when they run while standing, and when they die. Here are the steps:
- Select the Cucumber Man in the Hierarchy panel.
- In the Inspector panel, scroll to the bottom and click the Add Component button.
- Select Audio | Audio Source.
- Uncheck the Play On Awake box.
Normally, we would assign an AudioClip to our Audio Source component. Since our Cucumber Man will have more than one audio clip, we will not assign one here.
Our next step is to edit the BeetleNPC script. Open that script file and make the following modifications:
- Add the following member variables:
public AudioSource audioSource ...