Add simple audio system
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Utils;
|
||||
using Utils.Utils;
|
||||
|
||||
public class AudioManager : Singleton<AudioManager>
|
||||
{
|
||||
private AudioSource audioSource;
|
||||
|
||||
[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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user