Soundboard Template - Question
-
I had this problem too! Would be nice if someone responds :D
Comment actions -
Camille S you could add an audio component and change the SoundboardKey script to use the same audio component so it replaces any audio currently playing when another one is selected. The following code does that but it doesn't account for the trigger visuals in the original code. You will want to add the audio component to each SoundboardKey billboard in the inspector where it says "Single Audio Component."
// @input Asset.AudioTrackAsset audioTrack
// @input SceneObject triggerVisual
// @input bool useCustomHoldTime = false
// @input float customHoldTime = 0.8
//@input Component.AudioComponent singleAudioComponent
var audioComponent = script.singleAudioComponent; //get audioComponent
// Tapped event
function onTapped(eventData) {
print("Soundboard: " + script.getSceneObject().name + " - Key hit");
global.tweenManager.startTween(script.getSceneObject(), "press");
//set audio track when user taps
if (script.audioTrack ) {
audioComponent.audioTrack = script.audioTrack;
} else {
print("Soundboard: " + script.getSceneObject().name + " - Audio resource not set. Please add in the Inspector");
}
// Play sound
if (audioComponent) {
audioComponent.play(1);
} else {
print("Soundboard: " + script.getSceneObject().name + " - Audio resource not set. Please add in the Inspector");
}
}
var tapEvent = script.createEvent("TouchStartEvent");
tapEvent.bind(onTapped);Comment actions -
Thanks very much! Martin Sanchez
Comment actions
Please sign in to leave a comment.
Have a comment?