Implementing the Cucumber Man audio

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:

  1. Select the Cucumber Man in the Hierarchy panel.
  2. In the Inspector panel, scroll to the bottom and click the Add Component button.
  3. Select Audio | Audio Source.
  4. 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:

  1. Add the following member variables:
      public AudioSource audioSource ...

Get Getting Started with Unity 2018 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.