Search Unity

Muting Computer Speakers using C# scripts in Unity

Discussion in 'Scripting' started by FK22, Mar 18, 2019.

  1. FK22

    FK22

    Joined:
    Jul 7, 2017
    Posts:
    40
    Hi, Is there any way to access the computer speakers of my computer, and put the volume to 0 (mute) using C# script in Unity?

    Otherwise, is there any way to do this in Unity? I am using SteamVR in Unity and I cannot mute the audio. Any advice would be very helpful.
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    You can mute the game output if you wish by using a mixer and setting the master volume to 0. Now if you mean mute the speaker output so the sound only comes out of the vr headset, that is nothing to do with Unity. By default, the game outputs to the one audio device which would be the default device set in windows. SteamVR offers an option for the user to mirror the sound output to a separate device mainly so those watching in VR can also hear what is going on in the game/app.
     
  3. FK22

    FK22

    Joined:
    Jul 7, 2017
    Posts:
    40
    Hi, thanks for you answer. Well I want just to disable any sound or clips in my scene. How can I get the outputAudioMixer of the clip and put it to 0?

    In my Start function I have:

    Code (CSharp):
    1.         AudioSource car = CarClip.GetComponent<AudioSource>();
    2.  
    How can I get the output audio mixer from the car clip ad set it to 0?
     
  4. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035