RealiteeeyyyyTV

Untitled

Jan 4th, 2018
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class SoundLibrary : MonoBehaviour {
  6.  
  7. public SoundGroup[] soundGroups;
  8.  
  9. Dictionary<string, AudioClip[]> groupDictionary = new Dictionary<string, AudioClip[]>();
  10.  
  11. void Awake() {
  12. foreach (SoundGroup soundGroup in soundGroups) {
  13. groupDictionary.Add (soundGroup.groupID, soundGroup.group);
  14. }
  15. }
  16.  
  17. public AudioClip GetClipFromName(string name) {
  18. if (groupDictionary.ContainsKey (name)) {
  19. AudioClip[] sounds = groupDictionary [name];
  20. return sounds [Random.Range (0, sounds.Length)];
  21. }
  22. return null;
  23. }
  24.  
  25. [System.Serializable]
  26. public class SoundGroup {
  27. public string groupID;
  28. public AudioClip[] group;
  29. }
  30. }
Add Comment
Please, Sign In to add comment