0
\$\begingroup\$

I have the following scenario

  1. "Main menu" scene containing a game object with an audio source component and a music manager script.

  2. An "about us" scene

Music manager script :

using UnityEngine;
using System.Collections;
public class ManageMusic : MonoBehaviour {

public static ManageMusic Instance;

void Awake()
{

    if (Instance)
        DestroyImmediate (gameObject);
    else {
        DontDestroyOnLoad (gameObject);
        Instance = this;

    }
  }
}

When I click on the "about us" button, the Game Music object keeps on playing and I can hear the music, but when I return back to the main menu no music is playing. I can see that the music game object is not destroyed when I return to the main menu and the audio listener has the value of the volume set to 1 , but I can't figure out the problem.

\$\endgroup\$
1
  • \$\begingroup\$ Just read the tutorial page I linked you on stackoverflow and try to understand the concept, and implement the singleton as your code apparently doesn't work as intended. \$\endgroup\$
    – Varaquilex
    Commented Jan 13, 2015 at 15:27

1 Answer 1

1
\$\begingroup\$

Use DontDestroyOnLoad for the music player. Reference Also make sure that the music player is a singleton and is not instanciated when re-loading scenes.

See here for details

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .