Triggering Sounds

From Off Grid Wiki
Jump to navigation Jump to search

How to trigger audio events in your custom levels

There are several different ways that you might want to trigger audio events in the levels you build in LevelKit.

See Also: SoundIDs Sound List

Atmos TriggerEvents in your lua scripts

The easiest way to establish the type of sounds you want to set the scene with, without having to rely on the player walking through a certain trigger or location, is to declare them in the setup of your mission script.

Setting the atmopheric audio in the mission script

To do this we use the TriggerEvent call from the Sound Lua API.

-- Set atmospheric audio for level

-- Set music states for level

In the example above we are setting the music variation we want initially and then setting it to silent as we don't want the music to play at the beginning of the mission.

Atmos trigger volumes

We then go on to use the 'Atmos Sound Trigger' component on a game object wth a collider to set up a trigger volume that can set turn the music on when we reach a specific area in the level.

A trigger volume using the AtmosSoundTrigger component

All that we have to do here is create an empty GameObject, apply a box collider and the AtmosSoundTrigger.cs component in the inspector and then in the name feild write the soundID you want to call (from this handy list of the pool of Sounds (SoundIDs Sound List) available to you in the game). In the above instance we have called 'Set_State_MX_Mission_Gameplay' to change the mission music from silent to audible when the player walks up to the barrier office.

The Sound API derives from the under-the-hood system our sound designer put together in Wwise, the sound engine we are using in conjunction with Unity. If you would like to learn more about the structure underyling this then there is more info on the SoundIDs Sound List page.