Play Audio Clips In Sequence From Array To Audio Sources In Array
I'm working on a project where a PA system, with multiple audio sources in an array, needs to play a sequence of audio clips in order all at once. I've managed to get all the audio sources to play at once, and to get them to play a specified clip from the array, but getting them to play in sequence has been a challenge. I've tried using IEnumerators/coroutines to make them play the clip, wait while it's playing, and then play the next clip, but instead it either only plays from one audio source at a time, and then starts the whole sequence again on the next, or only plays the last clip. I suspect this is because it tries to play them all at once, ignoring the coroutine altogether. This is the script I've got at the moment
public AudioSource[] loudSpeaker;
public AudioClip[] monologues;
// Start is called before the first frame update
void Start()
{
OpeningMonologue();
}
// Update is called once per frame
void Update()
{
}
public void PlayLoudspeakers()
{
for (var i = 0; i < loudSpeaker.Length; i++)
{
loudSpeaker[i].Play();
}
}
public void OpeningMonologue()
{
for (var i = 0; i < loudSpeaker.Length; i++)
{
loudSpeaker[i].clip = monologues[0];
PlayLoudspeakers();
}
}
0, of course, being the first audio clip in the array. If I change that value, the selected clip changes, but I need them to all play in order, and I haven't been able to achieve that.
Your answer
Follow this Question
Related Questions
Please help! Audio not working in another class.. 0 Answers
How to create buttons that toggle the audio clip playing for a game object? 0 Answers
What causes weird cracking/popping sound when playing 3d sound 1 Answer
Getting nullReferenceException when respawning a gameObject and trying to access the audio source. 0 Answers