Implementing the Cucumber Beetle audio

In this section, we will configure the Cucumber Beetle 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 beetle prefab in the Project panel's Assets | Prefabs folder. If you have more than one prefab, be sure to use the one that is used in your game.
  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 Beetles will have more than one audio clip, we will not assign one here. 

Our next step is to edit the BeetleNPC script. Open that ...

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.