using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class AudioClipsHolder : MonoBehaviour {
public List<AudioClip> audioClipList;
public Dictionary<string, AudioClip> audioClipDic;
void Start()
{
foreach (AudioClip audioClip in audioClipList)
{
Debug.Log(audioClip.name);
audioClipDic.Add(audioClip.name, audioClip);
}
}
}
I drag some audios to the audioClipList using the editor. The “Debug.Log(audioClip.name)” works and will print the name of the first clip. Then an error is generated when the code gets to “audioClipDic.Add(audioClip.name, audioClip)”
The error is “NullReferenceException: Object reference not set to an instance of an object”
Can anyone tell me what is wrong with this code?
Thanks
Thank you! Now it's working correctly!
– Laiken