Verse Library verse

02 Device

Plays a one-shot sound effect when a player steps onto a trigger pad.

verse-library/verse-sound-triggered-sfx/02-device.verse

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# TRIGGERED SFX: play a sound the instant a player steps onto a pad.
#
# Wire a Trigger Device (the entry pad) and an Audio Player Device (the
# stinger) into the slots below. Each time someone enters the trigger zone,
# we fire the sound effect — the audio "doorbell" of your nightclub entrance,
# a whoosh as a player crosses the dance floor, a coin chime on a tile.
triggered_sfx_device := class(creative_device):

    # The zone that detects a player stepping in.
    @editable
    EntryPad : trigger_device = trigger_device{}

    # The one-shot sound effect to fire on entry.
    @editable
    StingerSfx : audio_player_device = audio_player_device{}

    OnBegin<override>()<suspends> : void =
        StingerSfx.Enable()
        # Handle one entry per loop iteration, forever.
        loop:
            # Block here until someone steps into the pad. The event sends the
            # ?agent that triggered it (false if it was fired by code).
            MaybeAgent := EntryPad.TriggeredEvent.Await()
            if (Agent := MaybeAgent?):
                # Heard-by-instigator setups can play just for that player.
                StingerSfx.Play(Agent)

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in