I want music to continue after un-pausing from where it stopped when you first paused.
my script so far:
var nextSong1 : int = 0;
var myPlaylist1 : AudioClip;
function Update() {
if ( Input.GetKeyDown("p") ){ // 'p' has been pressed
PlayNextSong1(); // play the next song
}
}
function PlayNextSong1 () {
if ( audio.isPlaying ) { // if there is audio playing
audio.Pause(); // stop it
audio.clip = myPlaylist1; // set the audio clip to the next in the array
audio.Play(); // start the 'nextSong' playing
}
if (audio.Pause ) { // if there is audio playing
audio.Play();
}
}
I know this is an old thread, but I came across this issue too and am using mp3’s to save space. I happen to instantiate an audio prefab and have multiple music/background sources, so I found it convenient to simply stuff the time value into the AudioSource (a in this case) localScale transform for safe keeping since the scale of a lone AudioSource GameObject is meaningless and I didn’t want to create some additional storage for this silly thing. Something like:
if (mute) {
a.Pause ();
a.transform.localScale = new Vector3(a.time,0,0);
} else {
a.Play ();
a.time = a.transform.localScale.x;
}
I’m using Unity 5.3.4f1 and the following (UnPause) makes the music resume at the point where it was paused. I use mp3s for my songs and the following is in Javascript.
if (paused == true) {
GetComponent.<AudioSource>().Pause();
}
else if (paused == false) {
GetComponent.<AudioSource>().UnPause();
}