Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cant find audiolistener methods

Discussion in 'Scripting' started by Robster95, Nov 12, 2020.

  1. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    I am trying to pause all of the audiosources in the game scene when I pause the game. I already have the pause working where it sets the game time.timescale = 0 and everything online that I see to pause the game audio says to use

    AudioListener.Pause()

    I am trying to use this on the main camera but I cant find the .Pause or other methods like volume or play either.

    Am I missing a library? I've tried the Audio library and that still didnt work.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,890
    You can Pause an AudioSource, not an AudioListener.

    There's also a global AudioListener.pause static property but that would preclude you from playing any sounds/music in a pause menu etc... unless you follow the docs and set "ignoreListenerPause" to true on those sounds.
     
    Robster95 likes this.
  3. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    Ok thank you so much! I tried this with pausing the audiosources themselves and it works perfectly. I may try this method in case I want to implement some pause menu music in the future!
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @Robster95

    Another way to mute audio would be to use AudioMixer. That way you could also add some cool effect to your audio, when you you pause the game (for example). Also this way you wouldn't have to stop the background music, as it might sound repetitive if music restarts every time you pause and then restart your game.

    https://docs.unity3d.com/Manual/AudioMixer.html
     
    Last edited: Nov 12, 2020
    Robster95 likes this.
  5. Robster95

    Robster95

    Joined:
    Jul 3, 2019
    Posts:
    154
    I'll definitely learn more about the AudioMixer! I am actually using it right now and have different volume levels for everything thats producing sound inside of the mixer already.