mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-28 20:32:14 +01:00
Update AudioManager.cs
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using UnityEditor.Audio;
|
||||
using UnityEngine.Audio;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
// This list contains all sounds which should be accessable by the audiomanager.
|
||||
// If you want to add a sound -> add a new item in the list VIA the inspector!
|
||||
public Sound[] sounds;
|
||||
|
||||
public static AudioManager instance;
|
||||
@@ -17,14 +19,14 @@ public class AudioManager : MonoBehaviour
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
|
||||
foreach(Sound s in sounds)
|
||||
{
|
||||
s.source = gameObject.AddComponent<AudioSource>();
|
||||
s.source.clip = s.clip;
|
||||
s.source = gameObject.AddComponent<AudioSource>(); // The Audio source where the "Player can hear through"
|
||||
|
||||
s.source.clip = s.clip;
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.loop = s.loop;
|
||||
@@ -37,9 +39,10 @@ public class AudioManager : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
// USE this to play a sound in other scripts: FindObjectOfType<AudioManager>().Play(name);
|
||||
public void Play(string name)
|
||||
{
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name); // searching for sound in Array where sound.name == name
|
||||
if(s == null)
|
||||
{
|
||||
Debug.LogWarning("Sound: " + s.name + " not found!");
|
||||
|
||||
Reference in New Issue
Block a user