Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine.Audio;
- using System;
- using UnityEngine;
- public class AudioManager : MonoBehaviour
- {
- public Sound[] sounds;
- // Start is called before the first frame update
- void Awake()
- {
- foreach (Sound s in sounds)
- {
- s.source = gameObject.AddComponent<AudioSource>();
- s.source.clip = s.clip;
- s.source.volume = s.volume;
- s.source.pitch = s.pitch;
- }
- }
- public void Play(string name)
- {
- Sound s = Array.Find(sounds, sound => sound.name == name);
- s.source.Play();
- }
- public void Play(int randomNumber)
- {
- Sound s = sounds[randomNumber];
- s.source.Play();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement