Applying Sound to the Coin Box

We’ll have our sound effect play on awake, in much the same way we handled the activation of our particle effect. We’ll set the sound effect to Play On Awake, causing it to play automatically when the disabled version of the coin box becomes active. Take the following steps to set it up:

1. Select an instance of the boxCoin_disabled Prefab in your Scene.

2. Click the Add Component button and select Audio > Audio Source.

3. Drag the coinBlock_01 sound file from the _audio directory into the Audio Clip field of the Audio Source Component.

4. Apply the changes to the Prefab and save it.

Play the game and try it out. Our coin boxes should now make a clear chiming noise when struck.

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation 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.