Disable Enable Audio by UI Trigger

Okay, I face the problem. Have falling down objects and sound. Play sound when objects fall. It has 10 iterations so I have 10 Behaviors that trigger audio with delay for each falling object. But, also have 3 pickers for different objects and sound. The question is how to disable the sound when I switch mode?

So here I play the sound by trigger

and here I try to disable sound by tap on the UI picker button

Your script has some syntax errors in it. Are you sure it’s even running? I think you’d see some errors in the console.

It can be simplified quite a lot, too. If you just want to toggle the audio asset on or off, you can do something like this: script.audio.enabled = !script.audio.enabled

The Logger is clear somehow. I guess its cuz a trigger onRecording
Anyway I have a 3 pickers and I need to enable 3 different sound for each picker.

is that a right script?

// -----JS CODE-----
// @input Asset.AudioTrackAsset audio

function onTrigger() {
script.audio.enabled = !script.audio.enabled
    }

global.behaviorSystem.addCustomTriggerResponse("my_trigger", onTrigger);


ohh its work now but when I tap on the Picker button :smiley:
and play all sound on all action :frowning: I think its might be another way to achieve it

You could try making a script with an array input of sfx, then the tap would swap out the active sound for the next one

General tip: It’s useful to look inside the default behavior script because you can pull things from there and get a better understanding of how the events are working.

Then you don’t need to rely on the behavior script! For me it’s easier to understand what is happening if I write the whole thing from scratch, as opposed to using some existing script

1 Like