Files

69 lines
1.6 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using Utils;
using Utils.Utils;
public class AudioManager : Singleton<AudioManager>
{
//aaaaa theres nicer syntax for this i think
protected override bool dontDestroyOnLoad()
{
return true;
}
private AudioSource audioSource;
private AudioSource musicAudioSource;
[SerializeField]
private List<GameEntry<AudioClip>> clips = new List<GameEntry<AudioClip>>();
[SerializeField]
private List<AudioClip> speech = new List<AudioClip>();
private
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
audioSource = GetComponent<AudioSource>();
audioSource.pitch = 1;
musicAudioSource = transform.Find("Music").GetComponent<AudioSource>();
musicAudioSource.loop = true;
if (!musicAudioSource.isPlaying)
{
musicAudioSource.Play();
}
}
public void PlaySound(string type)
{
audioSource.pitch = 1f;
audioSource.PlayOneShot(clips.ByKey(type));
}
public void PlaySpeechSound(bool pitchDown)
{
int index = Random.Range(0, speech.Count);
audioSource.pitch = pitchDown ? 0.5f:1f;
audioSource.PlayOneShot(speech[index], 1.5f);
}
void Update()
{
transform.position = Camera.main.transform.position;
}
public void PlayMusic()
{
if (musicAudioSource.isPlaying) return;
musicAudioSource.Play();
}
public void StopMusic()
{
musicAudioSource.Stop();
}
}