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

  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. if (Startmusic != null)
  13. {
  14. curMusic = Startmusic;
  15. Startmusic.Play();
  16. StartCoroutine(ChangeMusic(loopMusic, Startmusic.clip.length));
  17. StartCoroutine(ChangeMusic(loopMusic, gameLength - 10.0f));
  18. }
  19. }
  20. private void Update()
  21. {
  22. }
  23. IEnumerator ChangeMusic(AudioSource music, float musicTime)
  24. {
  25. while (musicTime > 0)
  26. {
  27. musicTime -= 1.0f * Time.deltaTime;
  28. yield return new WaitForEndOfFrame();
  29. }
  30. curMusic.Stop();
  31. curMusic = music;
  32. music.Play();
  33. }
  34. }