[SOLVED] Handle sound in my script

Hello!I’m new to playcanvas and i am trying to handle a sound on my scene.I have insert a sound in that way

How can i pause my sound in my script ?

I believe this is what you are looking for.

// pause all sounds
this.entity.sound.pause();
// pause a specific sound
this.entity.sound.pause('beep');

when i use “this.entity.sound.pause()” i get an error: Cannot read property ‘pause’ of undefined

That means that you don’t have a sound component on that entity. Perhaps you are using the wrong entity?

I’m using the sound entity

Should i use something else?

Can you share a link to your project?

https://playcanvas.com/editor/scene/556315

So it looks like you have the musicButton.js script on an Entity called musicbutton-default which doesn’t have a Sound component.

2 Likes

Thank you! You helped me a lot!

1 Like