Advertisement
dronkowitz

MusicController.cs

Aug 6th, 2021 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Audio;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class MusicController : MonoBehaviour
  8. {
  9.     public AudioSource asource;
  10.     public List<AudioClip> myclips = new List<AudioClip>();
  11.     // Start is called before the first frame update
  12.     void Start()
  13.     {
  14.        
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.        
  21.     }
  22.     public void Playmyaudio()
  23.     {
  24.         StopAllCoroutines();
  25.         StartCoroutine(PlaymyAudioCoroutine());
  26.     }
  27.     public IEnumerator PlaymyAudioCoroutine()
  28.     {
  29.         foreach (AudioClip a in myclips)
  30.         {
  31.             asource.clip = a;
  32.             asource.Play();
  33.  
  34.             while (asource.isPlaying)
  35.             {
  36.                 yield return new WaitForSeconds(Time.deltaTime);
  37.             }
  38.         }
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement