- Home /
 
Pause Audio Help
Hi!
I have a pause script where I pauses the time and the audio.
The problem I have is that I want to add some button sound effect to my pause menu, but it wont work because I have the code "AudioListener.pause = true;" when the game is paused.
Is there anyway I can make this work?
Answer by deltamish · Sep 22, 2014 at 06:07 PM
Hi, Rather than setting AudioListener to pause what you could do is get a list of all the audio sources
 // Try this piece of code 
 // This is in C# if you want in javascript just leave a comment
 
 import UnityEngine;
 
               import System.Collections.Genric; import System.Collections;
 public var  thisAudio:AudioSource; // Assign the audio source that will play the sound
 private var  sources:List<AudioSources> = new List<AudioSources>();
 
 function Start()
 {
   sources =  GameObject.FindObjectsOfType(AudioSources) as (AudioSource);
 
 }
 
 
 function Update()
 {
  if(Input.GetButton("Pause"))
 {
 
  Time.timeScale = 0;
  DisableAudio();
 thisAudio.Play();
     }else {
  Time.timeScale = 1;
 
  }
     }
     
    function DisableAudio()
     {
      for(int i=0; i < sources.Count;i++)
     {
      if(sources[i] != thisAudio)
       sources[i].volume = 0;
     
     
     }
     }
 
               for the Enabling the audio just do the reverse for what you did for the DiableAudio
Thanks for the answer. I would really appreciate it if you made it in javascript :)
Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Audio help. 1 Answer
Wierd error messages concerning audio play and pause? 1 Answer
Stop another sound from another script? 1 Answer
pause menu on android phone 1 Answer