0
\$\begingroup\$

I want my background music to keep playing on loop, but whenever I transition into another scene, the loop starts over.

Is there any way to have the scene record the last point of the music it plays, and in the next scene starts playing at that moment?

\$\endgroup\$
2
  • \$\begingroup\$ or don't make the BGM part of the scene \$\endgroup\$ Commented Dec 7, 2014 at 17:02
  • \$\begingroup\$ @ratchetfreak how so? \$\endgroup\$ Commented Dec 7, 2014 at 17:52

1 Answer 1

3
\$\begingroup\$

I managed to make it myself by making an Empty Object (BGM) where to place the music. Then, haivng a simple script attached to the object with the following code:

void Awake(){ DontDestroyOnLoad(gameObject); } 

And it became a persistent object, therefore it's not destroyed between scenes.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Keep in mind if you add your BGM object to every scene while testung you will have duplicates! Make sure that those components are singeltons or you will run out of memory. \$\endgroup\$ Commented Dec 8, 2014 at 10:36
  • \$\begingroup\$ @CodeClown yeah, I'm taking that into consideration. Thank you :) \$\endgroup\$ Commented Dec 8, 2014 at 18:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.