Hi all,
Working on music engine for a game and I cannot get this to work. I need to play several sounds from one c# script. This is what the load/play part of the code looks like right now:
public class music : MonoBehaviour {
string[] arrayGen0Files = // Array of Clips to load from the resources folder
{
"Gen0_Calm_AA", "Gen0_Calm_AB", "Gen0_Calm_AC", "Gen0_Calm_AD",
"Gen0_Calm_BA", "Gen0_Calm_BB", "Gen0_Calm_BC", "Gen0_Calm_BD",
"Gen0_Battle_AA", "Gen0_Battle_AB", "Gen0_Battle_AC", "Gen0_Battle_AD",
"Gen0_Battle_BA", "Gen0_Battle_BB", "Gen0_Battle_BC", "Gen0_Battle_BD",
};
AudioSource[] arrayGen0Sources; // Array of Sources
AudioClip[] arrayGen0Clips; // Array of Clips
void Start ()
{
for (int i=0; i < arrayGen0Files.Length; i++) // Load Clips
{
arrayGen0Sources *= (AudioSource)gameObject.AddComponent ("AudioSource");*
arrayGen0Clips = (AudioClip)Resources.Load (arrayGen0Files*);*
arrayGen0Sources_.clip = arrayGen0Clips*;*_
arrayGen0Lengths = arrayGen0Clips*.length;*
* }*
* }*
* void Update () // Play clips depending on currentListProgression*
* {*
* arrayGen0Sources[arrayGen0Playlist[currentListProgression]].Play ();*
* }*
}
It just ends up with me getting a “NullReferenceException” at the loading stage of the code. Is there a better way to handle a lot of files in one C# script?