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?

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 *!= thisAudio)*

sources*.volume = 0;*

}
}
for the Enabling the audio just do the reverse for what you did for the DiableAudio