- Home /
Question by
SofiaGarciaBarbes · Dec 27, 2019 at 05:25 PM ·
audioaudiosourceaudioclipwaitforsecondsaudio.play
Assign a clip to an AudioSource when it finishes playing.
Hi, I'm creating an application in which I need to play different clips in an array. Just when the first clip is finished, the second one should be played. My code is the following:
public AudioClip[] clips;
private AudioSource audiosource;
void Start()
{
audiosource = this.GetComponent<AudioSource>();
}
public void playClips()
{
Debug.Log("hola2"); //printed
for (int i=0; i < clips.Length; i++)
{
audiosource.clip = clips[i];
Debug.Log(clips[i].ToString()); //ok
audiosource.Play();
Debug.Log(audiosource.clip.length); //ok
Debug.Log(audiosource.isPlaying); //true ok
System.Threading.Thread.Sleep( (int) audiosource.clip.length+1); //not waiting
new WaitForSeconds(audiosource.clip.length); //not waiting
Debug.Log(audiosource.clip.length);
}
}
I tried with a yield return new WaitForSeconds(float), but my method should be void,as I am calling it from the OnClick() of a button.
Any idea of why is it not working?
Thank you in advance
Comment
Your answer
Follow this Question
Related Questions
Play audio at consistent volume 2 Answers
Looping an audio while holding "shift key" 1 Answer
Can an object check on other objects? 1 Answer
Audiosource.Play() not working 0 Answers
AudioSource.clip.time won't work? 2 Answers