Audio Manager
Description
Audio manager that groups clips by enum "categories".
An AudioManager is attatched to a GameObject for managing sound in a project. In order to play sounds with the AudioManager you need to also have an AudioSource on the GameObject the sound will be coming from.
You can play clips through the PlayClip function.
using UnityEngine;
public class CoinPickup : MonoBehaviour
{
private AudioSource _source;
private void Start()
{
//Fetch the AudioSource from the GameObject
_source = GetComponent<AudioSource>();
}
private void OnTriggerEnter(Collider other)
{
//If the player runs into this object
if(other.gameObject.tag == "Player")
{
//Play random audio clip of type Coin_Collected from the effectAudio list
AudioManager.Instance.PlayClip(_source, AudioManager.Instance.FindRandomizedClip(AudioType.Coin_Collected, AudioManager.Instance.effectAudio));
}
//If the player shoots this object with a bullet
if(other.gameObject.tag == "Bullet")
{
//Play specific audio clip of type Coin_Destroyed from the effectAudio list
AudioManager.Instance.PlayClip(_source, AudioManager.Instance.FindClip(AudioType.Coin_Destroyed, AudioManager.Instance.effectAudio));
}
}
}
Properites
ambientAudio | List of AudioGroup to organize the different ambient audio groups. |
effectAudio | List of AudioGroup to organize the different effect audio groups. |
Public Methods
FindClip | Searches through soundGroup to find the correct audioType. Then plays the first clip of that AudioType. |
FindRandomizedClip | Searches through soundGroup to find the correct audioType. Then plays a random clip of that audioType. |
FindClipTypes | Searches through soundGroup to find the correct audioType and returns a List of type AudioController. |
PlayClip | Plays the clip |
LoopRandomizedClips | Searches through audioController and picks a random sound to play on the source until stopped. |