init
This commit is contained in:
commit
862afc9b7a
478 changed files with 197737 additions and 0 deletions
50
Assets/Scripts/AudioManager.cs
Normal file
50
Assets/Scripts/AudioManager.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using UnityEngine.Audio;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class AudioManager : MonoBehaviour{
|
||||
|
||||
public Sound[] sounds;
|
||||
|
||||
public static AudioManager instance;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
if (instance == null)
|
||||
instance = this;
|
||||
else{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
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;
|
||||
s.source.loop = s.loop;
|
||||
|
||||
s.source.outputAudioMixerGroup = s.mixerGroup;
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogError("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.Play();
|
||||
}
|
||||
public void Stop(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogError("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.Stop();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue