using System.Collections; using System.Collections.Generic; using UnityEngine; public class MusicPlayer : MonoBehaviour { AudioSource source; void Start(){ source = GetComponent(); } private void OnEnable() { GameObject[] musicZones = GameObject.FindGameObjectsWithTag("MusicZone"); foreach (GameObject musicZone in musicZones) { musicZone.GetComponent().Pause(); }; source.Play(); } private void OnDisable() { source.Stop(); } }