class in UnityEngine.Audio
/
Inherits from:Object
/
Implemented in:UnityEngine.AudioModule
Object representing a group in the mixer.
Used to route audio to specific channels in an AudioMixer, allowing for grouped processing and effects.
Commonly used for managing different categories of sounds, like music, sound effects (SFX), and dialogue with shared volume controls and audio effect settings.
AudioMixerGroups can be nested for more complex audio hierarchies. Typically, a root "Master" group is used that contains multiple specific groups like "Music", "SFX" and "Dialogue".
using UnityEngine; using UnityEngine.Audio;
// Example of a class that manages audio in a game public class AudioManager : MonoBehaviour { // References to the AudioMixer and AudioSources public AudioMixer audioMixer; public AudioSource musicSource; public AudioSource sfxSource;
// Handles to the AudioMixerGroups private AudioMixerGroup musicGroup; private AudioMixerGroup sfxGroup;
private void Start() { // Find the AudioMixerGroups and set the output of the AudioSources to them musicGroup = audioMixer.FindMatchingGroups("Music")[0]; musicSource.outputAudioMixerGroup = musicGroup;
sfxGroup = audioMixer.FindMatchingGroups("SFX")[0]; sfxSource.outputAudioMixerGroup = sfxGroup;
SetMusicVolume(0.8f); SetSFXVolume(1.0f); }
public void SetMusicVolume(float volume) { // Set the volume of the Music group in the AudioMixer // Volume needs to be exposed in the AudioMixer audioMixer.SetFloat("MusicVolume", volume); }
public void SetSFXVolume(float volume) { // Set the volume of the SFX group in the AudioMixer // Volume needs to be exposed in the AudioMixer audioMixer.SetFloat("SFXVolume", volume); } }
Note: Create your AudioMixerGroups in the editor before referencing them in code.
Additional resources: AudioMixer, AudioSource, AudioListener.
Property | Description |
---|---|
audioMixer | Gain access to the AudioMixer that this AudioMixerGroup belongs to (Read Only). |
Property | Description |
---|---|
hideFlags | Should the object be hidden, saved with the Scene or modifiable by the user? |
name | The name of the object. |
Method | Description |
---|---|
GetInstanceID | Gets the instance ID of the object. |
ToString | Returns the name of the object. |
Method | Description |
---|---|
Destroy | Removes a GameObject, component or asset. |
DestroyImmediate | Destroys the object obj immediately. You are strongly recommended to use Destroy instead. |
DontDestroyOnLoad | Do not destroy the target Object when loading a new Scene. |
FindAnyObjectByType | Retrieves any active loaded object of Type type. |
FindFirstObjectByType | Retrieves the first active loaded object of Type type. |
FindObjectsByType | Retrieves a list of all loaded objects of Type type. |
Instantiate | Clones the object original and returns the clone. |
InstantiateAsync | Captures a snapshot of the original object (that must be related to some GameObject) and returns the AsyncInstantiateOperation. |
Operator | Description |
---|---|
bool | Does the object exist? |
operator != | Compares if two objects refer to a different object. |
operator == | Compares two object references to see if they refer to the same object. |