maxhacker11

SoundLibrary.cs

Jan 2nd, 2024
1,943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | Source Code | 0 0
  1. using UnityEngine;
  2.  
  3. [System.Serializable]
  4. public struct SoundEffect
  5. {
  6.     public string groupID;
  7.     public AudioClip[] clips;
  8. }
  9.  
  10. public class SoundLibrary : MonoBehaviour
  11. {
  12.     public SoundEffect[] soundEffects;
  13.  
  14.     public AudioClip GetClipFromName(string name)
  15.     {
  16.         foreach (var soundEffect in soundEffects)
  17.         {
  18.             if (soundEffect.groupID == name)
  19.             {
  20.                 return soundEffect.clips[Random.Range(0, soundEffect.clips.Length)];
  21.             }
  22.         }
  23.         return null;
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment