Hello, I have this code here that creates and destroys a main music system. The reason I want it to destroy the music is because in my level when I finish the level I want a special jingle to play but when the menu appears again (as of right now there is only one level) the music keeps playing. But now I get an error that says that the code is unsure of the variable I instantiated. How can I access the variable in another function?
This is the code of the stop music function.
public static function StopAllAudio() {
mManager.Destroy(AudioSource);
for(var audioS : AudioSource in allAudioSources) {
audioS.Stop();
}
}
and this is the code of the create music function.
function Start ()
{
currentScore = 0;
if (!GameObject.FindGameObjectWithTag("MM")) {
var mManager = Instantiate (musicPrefab, transform.position, Quaternion.identity);
mManager.name = musicPrefab.name;
DontDestroyOnLoad (mManager);
}
}
I want to access the stop music function from another script, so I can't pass the variable on. What do I do?
↧