i have got problem with sounds in unity. This is my code:
[RequireComponent(typeof(AudioSource))]
public class SoundManager : MonoBehaviour { public static SoundManager instance;
private AudioSource source;
public Dictionary<SOUND_TYPE,AudioClip> sounds;
public enum SOUND_TYPE
{
DEATCH,
CATCHED
}
// Use this for initialization
void Start()
{
source = GetComponent<AudioSource>();
loadSounds();
}
// Update is called once per frame
void Update ()
{
}
public void playSound(SOUND_TYPE type)
{
source.clip = sounds[type];
source.Play();
}
public void loadSounds()
{
//loading sounds
sounds.Add(SOUND_TYPE.DEATCH, Resources.Load<AudioClip>("Sounds/AccelerationLow"));
}
}
And i have an error at line with source.Add()
.
Error: NullReferenceException: Object reference not set to an instance of an object
I don't know what is going on and how can i repair it.