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();
|
|
}
|
|
}
|