0
\$\begingroup\$

I have the following scenario

  1. Main menu scene containing a gameobject with an audio source component
  2. An about us scene

gameObject script :

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

// Use this for initialization
    void Start () {

}

// Update is called once per frame
void Update () {

}
public static ManageMusic Instance;
void Awake()
{

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

    }
  }
}

when i click on aboutUs Button the Game Music object keep on playing an i can hear the music but when i return back to the main menu no music is still playing . i can see that the gameobject is not destroyed when i return to the main menu and the audio Listener have the value of the volume set to 1 , but i can't figure out the problem can anyone help me

\$\endgroup\$
  • \$\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 Jan 13 '15 at 15:27
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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.