- Home /
Question by
StarsideStudios · Jul 28, 2015 at 05:22 AM ·
unity5musicstopcontinue
Stop continuing music (Please Help)
Hello! I'm making a main menu and wanted continuous music running through each menu scene. The script does what I want. But when I load mission #1.. the music is still playing and wont stop. Please Help.
Script:
pragma strict
static var currentScore : int = 0;
var offsetY : float = 40; var sizeX : float = 100; var sizeY : float = 40;
var musicPrefab : Transform;
function Start () { currentScore = 0;
if (!GameObject.FindGameObjectWithTag("MM")) {
var mManager = Instantiate (musicPrefab, transform.position, Quaternion.identity);
mManager.name = musicPrefab.name;
DontDestroyOnLoad (mManager);
}
}
Comment
Answer by NeverHopeless · Jul 28, 2015 at 06:11 AM
Try like this:
// Identify your scene where you have to stop current running music and probably start new one
if(Application.loadedLevelName == "GameScene")
{
// Find the game object who is playing the audio and STOP audio clip.
GameObject.FindGameObjectWithTag("MM").GetComponent<AudioSource>().Stop();
}
Hope it helps!
It's also giving me this error http://gyazo.com/92cf6c24588be1bf0f0fd37e135a98cd
Sorry for the late response, this is the start function code.