Mute the World: Mastering the Audio Mixer API in Verse
verse-library
class StealthAudioScript is functional_game_script()
# We need a reference to the Audio Mixer device.
# In the editor, you'll link this to the Audio Mixer you placed.
audio_mixer_device: audio_mixer_device = audio_mixer_device{}
# We also need a Timer to simulate the "Prep Phase" ending.
# Link this to a Timer device in the editor.
timer_device: timer_device = timer_device{}
# This function runs when the game starts.
# It's like the "Battle Bus" dropping off players.
OnBegin<override>()<suspends>: void =
# First, let's make sure the footsteps are MUTED.
# We do this by activating the mix we set up in the editor (Volume 0.0).
# Since we unchecked "Activate on Game Start" in the editor,
# we have to call this manually to set the initial state.
audio_mixer_device.ActivateMix()
# Print a message to the debug console so we know it worked.
Print("Stealth Mode ON: Footsteps are muted!")
# This function is called when the Timer finishes.
# Link the Timer's "On Finish" event to this function in the editor,
# OR we can handle it in code if we started the timer ourselves.
# For this example, let's assume we start the timer in OnBegin.
StartTimer<override>()<suspends>: void =
# Start the timer for 10 seconds (the "Stealth Phase").
timer_device.Start(10.0)
# Wait for the timer to finish.
# <suspends> means this code pauses here until the timer ends.
timer_device.OnFinish()
# NOW, the stealth phase is over.
# Let's UNMUTE the footsteps.
# NOTE: In the editor, you'd need a SECOND Audio Mixer device
# set to Volume 1.0 (Unmuted) and link it to a variable like