Snaparazzi/Assets/Scripts/AudioManager.cs

52 lines
979 B
C#
Raw Normal View History

2024-01-28 14:42:54 +00:00
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}");
2024-01-28 14:42:54 +00:00
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");
2024-01-28 14:42:54 +00:00
sfxSource.PlayOneShot(_clip);
}
}
[System.Serializable]
public class MusicByTitle
{
public MusicTitle title;
public AudioClip clip;
}
public enum MusicTitle
{
Menu,
TakingPicture,
VotingSession,
Ending
}