You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

40 lines
943 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundManager : MonoBehaviour {
public AudioSource Startmusic;
public AudioSource loopMusic;
public AudioSource endMusic;
public float gameLength = 120;
AudioSource curMusic;
public void Start()
{
if (Startmusic != null)
{
curMusic = Startmusic;
Startmusic.Play();
StartCoroutine(ChangeMusic(loopMusic, Startmusic.clip.length));
StartCoroutine(ChangeMusic(loopMusic, gameLength - 10.0f));
}
}
private void Update()
{
}
IEnumerator ChangeMusic(AudioSource music, float musicTime)
{
while (musicTime > 0)
{
musicTime -= 1.0f * Time.deltaTime;
yield return new WaitForEndOfFrame();
}
curMusic.Stop();
curMusic = music;
music.Play();
}
}