How can i Pause and Unpause the music?

Hi, i’m simply trying to pause the music when the player dies to get the death sound feel better and then resume it , but everything i try is useless, i was trying to do something like this, but the music only stops, the death sound plays and never resumes , i tried several ways (like using stop and play, pause and unpause, with them outside the coroutine but it didn’t change nothing)

How can i do? :confused:

Hi Shinos,

The Pause method should stop the sound and when you call Play again it should resume.

What does FindObjectOfType().LoadGameOver(); do? Is it changing scenes?
If that’s the case I’d say that’s what’s going on, the scene changes, coroutine starts and stops the music but then is destroyed so never gets to the second part of the Coroutine

It’s possible that Destroy(gameObject); is also getting rid of the Coroutine

Hi mate, i tried to do it withouth changing the scene but the result is the same, i did another test, with this piece of code

BUT it only works with everything before the yield

it’s like he waits for ever, i crash with an enemy, the volume increase but the action after the delay are not executed, I tried also to put a Debug.log after the yield line but it doesn’t show up, i don’t know why it stops right there

the FindObjectOfType().LoadGameOver() has a coroutine in which he waits too before the change, so there is an amount of time before the scene changes so the coroutine should have enough time

I checked better and you are right my problem is due to the fact that the player object gets destroyed, if i delete the Destroy(gameObject) line it works, but now i have to figure how to do all of this correctly, i feel so dumb hahaha sorry

I DID IT, thank you for your help! ( even if i have an other little question, if you have time to help a little bit more i could ask you later)

i put my functions in the singleton MusicPlayer

and then i call it from my player so even if it gets destroyed it doesn’t matter

No need to feel dumb, this is all part of the learning process, great job on finding a solution!

Ask as many questions as you like I’ll try to answer to the best of my knowledge.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms