Programming Sound Triggers

Capture_03

Again with the sound I over-reached for my skill level. I again thought the audio would just be a matter of drag and drop – but it wasn’t at all. How the basic audio works is the character has an audio listener and you can place audio source into the scene as an invisible object. Unfortunately this plays the sound at the same volume no matter where you are in the scene from start to finish. This just wouldn’t work for triggering audio and placing multiple audio sources throughout the scene.

I ended up creating three C# Scripts:

(With help from outside source examples)

  • Audio that plays once when walk into
  • Audio that plays continuously once approached
  • Audio that plays only in a specific area.

The code connects the sound sources to the trigger collides in the scene so that when the character approaches the trigger the audio plays.

In future I would try and find a way to make the sound blend smoother and feather as you walk through the collider – I think it may just be a matter of changing the shape of the collider, but I could be wrong.