using System.Collections; using System.Collections.Generic; using UnityEngine; public class MusicManager : MonoBehaviour { static MusicManager instance; AudioSource intro; AudioSource gameplay; void Start() { AudioSource[] audioSources = GetComponents(); intro = audioSources[0]; gameplay = audioSources[1]; } void Awake() { if (instance == null) { instance = this; DontDestroyOnLoad(instance); } else Destroy(gameObject); } public void PlaySong(string songName) { StopOtherSongs(songName); if (songName == "intro" && !intro.isPlaying) intro.Play(); if (songName == "gameplay" && !gameplay.isPlaying) gameplay.Play(); } public void StopOtherSongs(string currentSongName) { if (currentSongName != "intro") intro.Stop(); if (currentSongName != "gameplay") gameplay.Stop(); } }