Having music persist between scenes but also change songs after a certain number of scenes? (Unity 3D)
Right now I have 11 levels, I have multiple songs. I want each 10 levels to be a world, where each world has a different song. I have an audio source in the player where the music comes from, so i can change the song depending on the level, but because each scene has a different player, the music doesnt persist so it restarts every level. the following code is in my playercontroller script thats in the player:
public AudioSource screamSource;
public AudioSource music;
public AudioSource first10;
public AudioSource Second10;
void Start()
{
Second10.volume = 0;
first10.volume = 1;
music = GetComponent<AudioSource>();
first10.Play();
DontDestroyOnLoad(first10);
}
if (other.gameObject.CompareTag("Finish")) {
other.gameObject.SetActive(false);
count = 0;
SetCountText();
sceneNum++;
string sceneName = "Level" + sceneNum;
SceneManager.LoadScene(sceneName);
Debug.Log("LoadLevel1");
}
if (sceneNum == 11)
{
Second10.volume = 0;
first10.volume = 1;
}
}
before this i had a music element that would persist but i could not get it to change after 10 scenes
Your answer
Follow this Question
Related Questions
Midi parser to rhythm game! 0 Answers
Reading Quaternion.eulerAngles.y smaller 45 and greater 315 does not work 0 Answers
How do I make my game look clean on IOS? 0 Answers
"next level" is not loading 0 Answers
Instantiate along the Z/X Axis only? 0 Answers