using System.Collections.Generic; using UnityEngine; using Utils; using Utils.Utils; public class AudioManager : Singleton { //aaaaa theres nicer syntax for this i think protected override bool dontDestroyOnLoad() { return true; } private AudioSource audioSource; private AudioSource musicAudioSource; [SerializeField] private List> clips = new List>(); [SerializeField] private List speech = new List(); private // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { audioSource = GetComponent(); audioSource.pitch = 1; musicAudioSource = transform.Find("Music").GetComponent(); 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(); } }