52 lines
979 B
C#
52 lines
979 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class AudioManager : MonoBehaviour
|
|
{
|
|
public AudioSource musicSource;
|
|
public AudioSource sfxSource;
|
|
public List<MusicByTitle> musics = new List<MusicByTitle>();
|
|
|
|
public static AudioManager Instance;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public void ChangeMusic(MusicTitle _title)
|
|
{
|
|
Debug.Log($"changing music to {_title}");
|
|
musicSource.clip = musics.Find(x => x.title == _title).clip;
|
|
musicSource.Play();
|
|
}
|
|
|
|
public void StopMusic()
|
|
{
|
|
musicSource.Stop();
|
|
}
|
|
|
|
public void PlaySFX(AudioClip _clip)
|
|
{
|
|
Debug.Log($"playing {_clip.name} SFX");
|
|
sfxSource.PlayOneShot(_clip);
|
|
}
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class MusicByTitle
|
|
{
|
|
public MusicTitle title;
|
|
public AudioClip clip;
|
|
}
|
|
|
|
public enum MusicTitle
|
|
{
|
|
Menu,
|
|
TakingPicture,
|
|
VotingSession,
|
|
Ending
|
|
}
|