I have a scene with about 20 game objects and when one is clicked, it begins playing audio. When the next on is clicked I need to stop any audio that’s playing and play the next audio. Everything I’ve found regarding this topic says to set Time.timeScale to 0, but all that’s going to do is pause everything. The other answer I keep seeing is that I should set AudioListener.volume to 0, which will be essentially muting everything.
Here’s what I currently have so far. I just need to insert something to stop all audio before a new track begins. Sorry if this is a simple request, I couldn’t find an answer anywhere!
function Update(){
if (audio.isPlaying){
transform.Rotate(.5, .25, .75);
}
}
function OnMouseDown(){
if (audio.isPlaying){
audio.Stop();
transform.rotation = Quaternion.identity;
}
else {
//Stop All Audio
audio.Play();
}
}
Well what you could do, is put all your audio sources into an array. And then when you want to stop all audio, just cycle through the array with a for loop stopping all the audio sources and then start playing the new audio source.
None of this code is tested, so just use it as a reference.
private AudioSource arrAudio;
Start()
{
//Declare the array here and place your audio sources inside of it.
}
Update()
{
for(var int i=0; i < arrAudio.length; i++)
{
arrAudio*.stop();*
}
arrAudio*.Play(); //This is to play the new audio source.*
} So try something like that, and see if it works for you.
this turns them on and off still need to find some way to look if there is sound playing and stop that. sadly enough if(audio.isPlaying){audio.stop();} doesn’t work
Hey @imnickb,
I know it’s pretty late to answer on this topic.
And maybe the answer I provide has simply not available at the time you’ve been asking but how about just pausing your AudioListener:
Regards,Hey imnickb,
I know it’s pretty late to answer on this topic.
And maybe the answer I provide has simply not available at the time you’ve been asking but how about just pausing your AudioListener:
void Start() {
allAudio = FindObjectsOfType<AudioSource>(); //Find All AudioSources
for(int i =0; i<allAudio.Length;i++){
allAudio_.Stop(); //Stop All AudioSources Using The **for** loop_