I’m trying to load an array of MP3 files from the Resources folder, and then assign each MP3 file to the Audio Clip value of a GameObject.
This list of GameObjects (referred to as “Notes”) is sorted, and the MP3 files are already sorted manually (their names are in numerical order).
Below is my attempt, I’ve removed the sorting method SortNotes() to save space (it works perfectly fine, isn’t the issue).
// An array of Notes
public GameObject[] NotesArray;
AudioClip[] pickupMP3s;
// Use this for initialization
void Start () {
// Grab and sort array of Notes
NotesArray = GameObject.FindGameObjectsWithTag("Note");
SortNotes();
// Grab a list of pick-up mp3 files
pickupMP3s = Resources.LoadAll("..\\Level 4\\Level 4 Pickup Tracks") as AudioClip[];
}
// Assign each mp3 file to a Note
void AssignNotes(){
for (int i = 0; i < NotesArray.Length; i++){
foreach (GameObject note in NotesArray){
try{
note.audio.clip = pickupMP3s*;*
_ Debug.Log(pickupMP3s*);_
_ Debug.Log(note.audio.clip.name);_
_ }catch(Exception e){_
_ Debug.Log(e.ToString());_
_ }_
_ }_
_ } _
_}_
_I get tons of NullReferenceException: Object reference not set to an instance of an object errors. They seem to stem from this line: note.audio.clip = pickupMP3s; but I can’t figure out what.*
The objects already have Audio Sources attached._