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.

36 lines
844 B

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class SoundManager : MonoBehaviour {
  5. public AudioSource Startmusic;
  6. public AudioSource loopMusic;
  7. public AudioSource endMusic;
  8. public float gameLength = 120;
  9. AudioSource curMusic;
  10. public void Start()
  11. {
  12. Startmusic.Play();
  13. StartCoroutine(ChangeMusic(loopMusic, Startmusic.clip.length));
  14. StartCoroutine(ChangeMusic(loopMusic, gameLength - 10.0f));
  15. }
  16. private void Update()
  17. {
  18. }
  19. IEnumerator ChangeMusic(AudioSource music, float musicTime)
  20. {
  21. while (musicTime > 0)
  22. {
  23. musicTime -= 1.0f * Time.deltaTime;
  24. yield return new WaitForEndOfFrame();
  25. }
  26. curMusic.Stop();
  27. curMusic = music;
  28. music.Play();
  29. }
  30. }