Beispiel #1
0
    public void PlayOneShot(AudioClip clip, AudioMixerGroup mixerGroup = null, float volume = 1, float pitch = 1)
    {
        if (mixerGroup == null)
        {
            mixerGroup = AudioMixer.FindMatchingGroups("SFXMaster/SFX")[0];
        }

        var audioSourceObject = _audioSourcePool.GetAudoSourceObject();
        var audioSource       = audioSourceObject.GetAudioSource;


        audioSource.clip   = clip;
        audioSource.volume = volume;
        audioSource.pitch  = pitch;
        audioSource.outputAudioMixerGroup = mixerGroup;

        audioSource.Play();

        _audioSourcePool.ReturnToPoolOnNotPlaying(audioSourceObject);
    }