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