using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
public class AudioManager : MonoBehaviour
{
public static AudioManager Instance;
public Sound musicSounds, sfxSounds;
public AudioSource musicSource, sfxSource;
private void Awake()
{
if(Instance == null){
Instance = this;
DontDestroyOnLoad(this.gameObject);
}
else
{
Destroy(gameObject);
}
}
private void Start() {
}
public void PlayMusic(string name)
{
Sound s = Array.Find(musicSounds, x => x.name == name);
if(s == null){
Debug.Log("MUSIC Not Found");
}
else{
musicSource.clip = s.clip;
musicSource.loop = true;
musicSource.Play();
}
}
public void StopMusic(string name)
{
Sound s = Array.Find(musicSounds, x => x.name == name);
if (s == null){
Debug.Log("MUSIC Not Found");
}
else{
musicSource.clip = s.clip;
musicSource.Stop();
}
}
public void Random()
{
musicSource.loop = false;
Sound clip = musicSounds[UnityEngine.Random.Range(1, musicSounds.Length)];
musicSource.PlayOneShot(clip);
}
public void PlaySFX(string name)
{
Sound s = Array.Find(sfxSounds, x => x.name == name);
if (s == null)
{
Debug.Log("SFX Not Found");
}
else
{
sfxSource.PlayOneShot(s.clip);
}
}
public void ToggleMusic(){
musicSource.mute = !musicSource.mute;
}
public void ToggleSFX(){
sfxSource.mute = !sfxSource.mute;
}
public void MusicVolume(float volume){
musicSource.volume = volume;
}
public void SFXVolume(float volume){
sfxSource.volume = volume;
}
}