Is there a way to update the audioclip of an object pooled audiosource instance?

Hello,

I have an object pool of audiosource instances that I’d like to change the default audioclip of during runtime. I’m a complete noob to coding, sorry if the question is very basic :slight_smile:

I’ve got this in the Start method. Is there maybe something I can add to the Update function to change the default audioclip of the instantiated objects?

void Start () {

	pooledAudios = new List<AudioSource> ();

	for (int i = 0; i < pooledAmount; i++) {
		AudioSource audio = (AudioSource)Instantiate (pooledAudioSource);
		audio.gameObject.SetActive (false);
		pooledAudios.Add (audio);
	}
		
}

HUGE thanks to anyone who can help! :slight_smile:

Sorry, this is my full ObjectPooler script:

public class ObjectPooler : MonoBehaviour {

public AudioSource pooledAudioSource;
public int pooledAmount = 10;
public bool willGrow = true; //lets the audiosource list grow if it's needed.

List<AudioSource> pooledAudios;

	
void Start () {

	pooledAudios = new List<AudioSource> ();

	for (int i = 0; i < pooledAmount; i++) {
		AudioSource audio = (AudioSource)Instantiate (pooledAudioSource);
		audio.gameObject.SetActive (false);
		pooledAudios.Add (audio);
	}
		
}

void Update(){

}
			

public AudioSource GetPooledAudio(){

	for(int i = 0; i < pooledAudios.Count; i++){

		if(!pooledAudios*.gameObject.activeInHierarchy){*

_ return pooledAudios*;_
_
}_
_
}_
_
if (willGrow) {*_

* AudioSource audio = (AudioSource)Instantiate (pooledAudioSource);*
* pooledAudios.Add (audio);*
* return audio;*
* }*
* return null;*
* }*
}
And this my SoundSwap script, which works fine on non-list audio:
* public AudioSource zone;*
* public AudioClip clip1;*
* void OnTriggerEnter2D(Collider2D other){*
* if (other.gameObject.tag == “player”) {*
// Debug.Log (“audio clip swapped”);
* zone.clip = clip1;*
* }*
* }*