I have multiple audio sources through out the scene. I created a coroutine so the audio loops through all the audio sources.
public List<AudioSource> sourcesInScene; //assign these in the inspector
private List<int> indexCountA = new List<int>();
public void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
ResetIndexCountA(sourcesInScene.Count);
StartCoroutine(RandomPlayBack());
}
private void ResetIndexCountA(int number)
{
indexCountA.Clear();
for (int i = 0; i < number; i++)
{
indexCountA.Add(i);
}
}
IEnumerator RandomPlayBack()
{
//we're using an ienumerator so we can "wait" between loops.
while (indexCountA.Count != 0)
{
for (int x = 0; x < sourcesInScene.Count; x++)
{
var i = Random.Range(0, indexCountA.Count);
sourcesInScene[indexCountA*].Play();*
indexCountA.RemoveAt(i);
yield return new WaitForSeconds(1f);
}
yield return null;
}
}
My question is on the line where I wrote “yield retrun new WaitForSeconds(1f);” instead of me specifing the yield time such as 1f how can I make it so it loops as soon as the previous audio is finished playing. Remember am not just playing audio clips, where i could yield using audioclip.length. I am working with multiple audio sources.
,