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.
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.
To do this we use the TriggerEvent call from the Sound Lua API.
-- Set atmospheric audio for level Sound.TriggerEvent("Set_Atmos_EXT_Harbour_Small") -- Set music states for level Sound.TriggerEvent("Set_MX_Mission_2") Sound.TriggerEvent("Set_State_MX_Mission_Silent")
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.
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 Sound IDs 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 How the SoundIDs are structured page.
Suggested next topic to read up on: Device Scripting