This commit is contained in:
GamerClassN7 2021-01-31 12:02:31 +01:00
parent 672cdf8db8
commit 10208a4bbc
2 changed files with 8 additions and 0 deletions

View File

@ -10,12 +10,15 @@ public class AudioManager : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
public void Awake() public void Awake()
{ {
DontDestroyGameobjectOnLoad(gameObject);
foreach (AudioSound c in clips) foreach (AudioSound c in clips)
{ {
c.source = gameObject.AddComponent<AudioSource>(); c.source = gameObject.AddComponent<AudioSource>();
c.source.clip = c.clip; c.source.clip = c.clip;
c.source.volume = c.volume; c.source.volume = c.volume;
c.source.pitch = c.pitch; c.source.pitch = c.pitch;
c.source.loop = c.loop;
} }
} }
@ -23,6 +26,9 @@ public class AudioManager : MonoBehaviour
public void Play(string name) public void Play(string name)
{ {
AudioSound s = Array.Find(clips, sound => sound.name == name); AudioSound s = Array.Find(clips, sound => sound.name == name);
if (s == null) {
return;
}
s.source.Play(); s.source.Play();
} }
} }

View File

@ -12,6 +12,8 @@ public class AudioSound
[Range(0.1f, 3f)] [Range(0.1f, 3f)]
public float pitch; public float pitch;
public bool loop = false;
[HideInInspector] [HideInInspector]
public AudioSource source; public AudioSource source;
} }