Hi I’m working a project and one of the tasks I’m trying to do is create a sound menu so I can test how all the sounds work in game, and what I have been trying to do is put all of the sounds in my project into an array and then use it to make a menu here’s my code. so far all it does is play all the sounds.
#pragma strict
var sounds : GameObject[];
var SoundByte : GameObject;
//var vert : int = 80;
function Start ()
{
var soundClips : Object[] = Resources.LoadAll("Sounds", AudioClip);
for (var count=0;count<soundClips.length;count++)
Debug.Log((soundClips[count] as AudioClip).name);
Debug.Log("soundClips size: "+soundClips.length);
for(var sound : int = 0; sound < soundClips.length; sound++)
{
var soundPrefab : GameObject = Instantiate(SoundByte);
soundPrefab.AddComponent(AudioSource);
audioPart = soundPrefab.GetComponent(AudioSource);
//audioPart.clip = Resources.Load(soundClips[sound]);
var sndClip : AudioClip = (soundClips[sound] as AudioClip);
soundPrefab.audio.clip = sndClip;
Debug.Log("sound is at: "+sound);
//GUI.Button (Rect (20,70,vert,20), "Level 2") ;
//vert++;
}
//var speaker : AudioSource = sounds[1];
//speaker.Play();
}