Hello, I’m a beginner in coding in Unity and I need help in implementing skipping song after pressing selected key, because I tried to do it but without any luck. For now I have only music player that plays all songs I put in it. What I want is that after I press selected key, the next song plays and after reaching the end of playlist it goes back to the first song. Thanks in advance for all answers. Here’s the script for playing music:
public class MusicPlayer : MonoBehaviour
{
public AudioSource audioSource;
public AudioClip[] soundtrack;
int i = 0;
void Start ()
{
StartCoroutine(PlayMusic());
}
IEnumerator PlayMusic ()
{
yield return null;
for (; i < soundtrack.Length; i++)
{
audioSource.clip = soundtrack*;*
audioSource.Play();
while (audioSource.isPlaying)
{
yield return null;
}
}
}
}