LieutenantChampignon/Projet Unity/Lieutenant Champignon/Assets/Scripts/MusicPlayer.cs

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();
}
}