- Home /
Triggering multiple audio clips to play in sequence
Ok so I'm quite new to programming and all the rest and I'm just wondering how I'd go about programming something in C#
so what's happening here is it's basically like a clock with four inner sections and three outer sections. I've made it so that the small hand completes a revolution in the time that the big hand passes through one section. I have it so that it lists it's location e.g. big hand: 1 small hand: 3, relative to what section each one is in.
How would I go about playing audio so that for example, when the big hand is in section 1, audio1 plays and when the small hand is in section 5, audio 5 plays after audio1?
I would have 7 audio clips, 1 for each section. How can I access them from script and how would I play the two audio clips in sequence?
Thanks for reading/answering and sorry if this is a dumb question or I've done messy work so far.
Answer by TheFloatingSheep · Dec 31, 2016 at 07:09 PM
I'm not quite sure how the syntax for this would go in C# so I'll just try to explain it rather than write the code:
You first need to make an array of AudioClip type variables, you can't change the length of an array like this at runtime but hopefully you won't need to do that. Then you go into the inspector, change the length to 7 in your case, and assign every clip in order. Then you use GetComponent to get the AudioSource component, assign one of your clips by typing = YourAudioClipArray[numberofclipcountingfrom0 - as integer obviously];
Now... from what I understand your script is counting from 1 to 7, computers always count from 0, so, basically your first audioclip will be name[0] instead of [1], based on the same logic 7 will be 6 and so on, so you could theoretically knowing on which segment the hand of your clock thing is, assign the item with that same number minus 1. Then use the play method of the audio source component.
Cheers.
Thanks so much! That was extremely useful and well explained, I managed to figure it all out.