using System.Collections; using System.Collections.Generic; using UnityEngine; public class MusicController : MonoBehaviour{ public AudioSource music; // The music for the level // Start is called before the first frame update void Start(){ // Get the music component and play it music = GetComponent(); music.Play(); // Delay the music slightly before restating StartCoroutine(PlayMusicAfterDelay(music.clip.length + 2f)); } // Coroutine for replaying the music IEnumerator PlayMusicAfterDelay(float delay){ yield return new WaitForSeconds(delay); music.Play(); StartCoroutine(PlayMusicAfterDelay(music.clip.length + 2f)); } }