Ok so what I need is for a song to play no matter what scene the player is in. For example, right now when the player is going through menus, the song starts over every time. Its gets very annoying. Any suggestions on how to solve this problem? Thanks! (again :P)
I’d imagine DontDestroyOnLoad would be what you’re looking for.
call DontDestroyOnLoad(this) on your gameobject that has the audio source attached to it.
Can you please provide an example of the layout for this script. Thanks!
This is what I have so far… (am I on the right path?)
var song : AudioClip;
function Update () {
DontDestroyOnLoad(song);
}
No, you need to call it on the gameobject where the audio source has been attached to.
And you only need to call it once. ( not in an update function )
So in a script thats attached to the same gameobject where the audio source is, add ‘DontDestroyOnLoad(this)’
It’s clearly show in the script ref :
I can’t seem to get it to work. Can you post a small example if you could? Thanks a lot
The game object with the AudioSource, playing the music must not be destroyed. So…
I am trying to figure this out, Im not much of a scripter (obviously) Thanks for everyones patience lol
make a new js script, add it to the gameobject with the audio source, open the script and add :
function Awake () {
DontDestroyOnLoad (this);
}
Ohhh see in the part that said (this) I though I was supposed to change that. Well it works but when I go back to the previous menu, it makes another sound file and plays 2 at the same time. I might be able to fix that.
yes, if you reload the same scene where the audio starts, it will start it again. you have to check if the audio is playing and if it is then don’t start it.
is what i mentioned before also