public static AudioSource PlaySound(AudioSource audioSource) { audioSource.CreatePool(); AudioSource spawnedAudio = audioSource.Spawn <AudioSource>(); instance.StartCoroutine(instance.PlayAudioCoroutine(spawnedAudio)); return(spawnedAudio); }
public static AudioSource PlaySound(AudioSource audioSource) { // Each AudioSource prefab gets its own pool of objects that match its settings. audioSource.CreatePool(); AudioSource spawnedAudio = audioSource.Spawn <AudioSource>(); // We mark the audio source as don't destroy on load so we can reuse our audio source // pool between scenes. This also allows sounds to continue to be played during scene loads. DontDestroyOnLoad(spawnedAudio.gameObject); instance.StartCoroutine(instance.PlayAudioRoutine(spawnedAudio)); return(spawnedAudio); }