- Home /
How to trigger sequential audio clips in an array when two objects collide?
The idea is that when two non-player characters meet, they adopt each others' audio clip to add to their default one. For example when character 1 (with a default 1.wav) meets character 2 (with a default 2.wav), 1's playlist becomes 1.wav-2.wav, and then 1 meets 3, their playlist then becomes 1.wav-2.wav-3.wav and so on.
Is there any code for adding audio clips to an array when two objects collide? Or, to set an array with every sound to possibly be played—then how can I write the code so that when two objects collide, certain sequential sounds (more than one but not all) in that array are triggered?
Answer by KloverGames · Apr 29 at 03:16 AM
Are you familiar with lists?
using System.Collections.Generic;
You would define a list of type AudioSource.
Then whenever the trigger happens or when you decided to stack the audio sources sequentially, just say npcAudioSources.Add( whatever audiosource you want );
Your answer
