Advertisement
Guest User

Overloaded Play

a guest
Mar 25th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine.Audio;
  2. using System;
  3. using UnityEngine;
  4.  
  5. public class AudioManager : MonoBehaviour
  6. {
  7.     public Sound[] sounds;
  8.  
  9.     // Start is called before the first frame update
  10.     void Awake()
  11.     {
  12.         foreach (Sound s in sounds)
  13.         {
  14.             s.source = gameObject.AddComponent<AudioSource>();
  15.             s.source.clip = s.clip;
  16.  
  17.             s.source.volume = s.volume;
  18.             s.source.pitch = s.pitch;
  19.         }
  20.     }
  21.  
  22.     public void Play(string name)
  23.     {
  24.         Sound s = Array.Find(sounds, sound => sound.name == name);
  25.         s.source.Play();
  26.     }
  27.  
  28.     public void Play(int randomNumber)
  29.     {
  30.         Sound s = sounds[randomNumber];
  31.         s.source.Play();
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement