Search Unity

Route Audio Source to Audio Mixer via script

Discussion in 'Scripting' started by Bologi, Sep 14, 2019.

  1. Bologi

    Bologi

    Joined:
    May 17, 2018
    Posts:
    4
    I created an audio manager following a tutorial from brackeys but I want to route some audio sources to an audio mixer and control the volume. Problem is the audio sources have no output field to connect with an AudioMixer. How can I add the output field on the audio source via script (C#) so I can route it to my Audio Mixer
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    656
    You would set the output mixer group, like so

    Code (CSharp):
    1.         public AudioMixerGroup MyMixerGroup;
    2.  
    3.         public void AssignMixer(AudioSource source)
    4.         {
    5.             source.outputAudioMixerGroup = MyMixerGroup;
    6.         }
     
    Bologi likes this.
  3. Bologi

    Bologi

    Joined:
    May 17, 2018
    Posts:
    4
    I haven't tested this but I think it should work. I will get back to you if it works. Thanks a lot!!!
     
  4. Bologi

    Bologi

    Joined:
    May 17, 2018
    Posts:
    4
    It works!!! Thanks, you are a game saver