- Home /
problems with continuous audio between scenes
hello, I am new to programming and I need some help with audio ... I have a series of five scenes, and wanted the music played in scene 1, continue playing without interruption when I go to scene 2, 3, and so on when using Application.LoadLevel ...
could someone help me? I'm doing the scrip in C # ... thank you in ...
Wow! Perfect guys! Works perfectly! You are very good!
Have one last thing I need to ask: I'm doing an initial menu, and it has the Play, Options and Quit options. By staying transitioning between Play> Options / Options> Play, the music continues to play, but when you click Play, I need it to stop ...
Can anyone help me with this last question?
First you need to get the audiosource. One way to do that is to declare a field to hold the (at top of script)
public AudioSource audioSource;
Then, in start, get the audio source:
audioSource = this.gameObject.GetComponent(); (or you should be able to drag it in)
Now, you will be able to interact with it. To stop the song you need enter this instruction in the play button.
audioSource.Stop();
You may also want to look into fading the volume out, by using audioSource.volume.
Answer by DMCH · Apr 15, 2014 at 03:50 PM
In the awake function of the script attached to the audio object, try adding:
DontDestroyOnLoad(gameobject);
This will prevent the object and any attached scripts from being destroyed between scenes. Not sure how it will work with music, as I've never needed to have continuous audio, but it's worth a go. Let us know how it goes.
worked perfectly, but now have another problem ... when I go back to the first scene, the music keeps playing, and at the same time, it starts at the bottom ... ie ...
two songs playing at the same time ...
Your answer
Follow this Question
Related Questions
Continuous music on selected scenes? 2 Answers
Play Audio Through Scenes 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity 5.3 How to load current level 3 Answers