Not playing sound at same time

I’m nearly done with my music application.
The five buttons on the right hand side should not play at the same time.
Currently if multiple buttons out of the 5 are clicked they play together. Is there a way to make sure only the button that is clicked first plays. And after that finishes the next button can be played.

Editor - https://playcanvas.com/editor/scene/896589
Code Editor - https://playcanvas.com/editor/code/674640?tabs=29641962
The JS is called Audio.js under Audio Clips > AudioScripts

Thank you

1 Like

You should stop the current sound playing, and then start playing another one:

// stop all sounds on this entity
this.entity.sound.stop();
// stop a specific sound
this.entity.sound.stop('PopSound');

// starts playing a sound
this.entity.sound.play('JazzSound');

https://developer.playcanvas.com/en/api/pc.SoundComponent.html#stop

1 Like

Hi @Leonidas

Thank you for your help.
It worked.

1 Like