Hey there,
I’m trying to create a sound library for my game, which plays one song after the other. Here is my code:
using UnityEngine;
using System.Collections;
public class GameSound : MonoBehaviour {
public AudioClip FirstTrack;
public AudioClip SecondTrack;
void Awake () {
DontDestroyOnLoad(this);
FirstSong();
}
IEnumerator FirstSong() {
audio.clip = FirstTrack;
audio.Play();
yield return new WaitForSeconds(FirstTrack.length);
SecondSong();
}
IEnumerator SecondSong() {
audio.clip = SecondTrack;
audio.Play();
yield return new WaitForSeconds(audio.clip.length);
}
}
I did use the unity reference guide. But it doesn’t work still, can someone please tell me why?
Ah thank you, i completely forgot about coroutines haha :)
– Iceblitzyt