Hello,
A while ago someone on here helped me fix this script(below) for which I am very greatful, but we couldn’t get the audio to resume from where it was when the pause menu was exited. The music just started over. Which wasn’t much of a problem until now. The reason it is now is beacuse I have more sounds in there so when the pause menu is exited all the ingame sounds play. I believe it has something to do with the array of audio sources that is a private variable, but if I change that then I have a feeling they will not stop at all when the pause menu is entered. All I want is for the sounds to contiune to stop when paused but when unpaused they continue from where they left off, or not play until they are supposed to. How would I go about this? Does anyone have an example? This is the script im using.
var pause : boolean = false;
var clickTexture : ClickTexture[];
private var allAudioSources : AudioSource[];
function Awake()
{
EnableClick( false );
for( var i : int = 0; i < clickTexture.Length; i++ )
{
clickTexture*.pauseScript = this;*
-
}*
-
allAudioSources = FindObjectsOfType(AudioSource) as AudioSource;*
}
function PauseAllAudio()
{
-
for(var audioS : AudioSource in allAudioSources)*
-
{*
-
audioS.Pause();*
-
}*
}
function ResumeAllAudio()
{
- for(var audioS : AudioSource in allAudioSources)*
-
{*
-
audioS.Play();*
-
}*
}
function Update()
{
-
if(Input.GetKeyUp(KeyCode.Escape))*
-
{*
-
pause = !pause;*
-
if(pause == true)*
-
{*
-
Time.timeScale = 0.0;*
-
EnableClick( true );*
-
PauseAllAudio();*
-
}*
-
else*
-
{*
-
Time.timeScale = 1.0;*
-
EnableClick( false );*
-
ResumeAllAudio();*
-
}*
-
}*
}
function RunOption( str : String )
{
- if( str == “quit” )*
- {*
-
Time.timeScale = 1.0;*
-
Application.LoadLevel("AliensMainMenu");*
- }*
- else if( str == “resume” )*
- {*
-
Time.timeScale = 1.0;*
-
EnableClick( false );*
-
ResumeAllAudio();*
- }*
}
function EnableClick( b : boolean )
{
- for( var i : int = 0; i < clickTexture.Length; i++ )*
- { *
_ clickTexture*.Show(b);_
_ }*_
}