Triggering sound through player interaction
All the sounds we’ve created so far are sounds that will play as soon as you enter a scene. This happens because we have Play On Awake checked in the Audio Source component.
If we don’t have this checked, sounds will never play. But what’s cool is we get to trigger sounds in other ways!
Triggering sound through Unity events
Let’s get a sound for our first stairs puzzle. This one will be quite easy. The easiest way for us to add our sound will be to add an Audio Source component directly to the trigger region GameObject. Let’s find LeftStairsTrigger
and scroll down in the Inspector until we find the Interactio Trigger script, as shown in Figure 10.20.
Figure 10.20: Interaction Trigger script on the LeftStairsTrigger GameObject
If you recall, we made a UnityEvent
called OnInteract
, which we can utilize with our Audio Source component! Go ahead and click Add Component at the bottom...