39 lines
955 B
C#
39 lines
955 B
C#
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<AudioSource>();
|
|
intro = audioSources[0];
|
|
gameplay = audioSources[1];
|
|
}
|
|
|
|
void Awake()
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = this;
|
|
DontDestroyOnLoad(instance);
|
|
}
|
|
else Destroy(gameObject);
|
|
}
|
|
|
|
public void PlaySong(string 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();
|
|
}
|
|
}
|