Put many many many prefabs in an array?

Hi, what if I have a folder with many prefabs, too many to pass to the script by hand in the editor. Is there a way in which I could call them from within the script? (instead of dragging them one by one on the script in the editor)

right now, this is that I do

var monkeyPrefab : GameObject;
var lettucePrefab : GameObject;
var shoePrefab : GameObject;
//and so on....

and then I click drag the prefabs from the project onto the script, one by one

but, what I’d like to do is something like this

var myPrefabs : GameObject[];

Function Start(){
     myPrefabs = [B]GetPrefabsFromFolders("AllModels/Prefabs/");[/B]
}

GetPrefabFromFolder would be the function I’d need to do what I want, is there a real method to do this?

For quite some time I’ve been wondering this.So far the only way to communicate with my prefabs was using the editor.

With scripting…I can access every object in the SCENE, but if I want to access stuff in the PROJECT files, click and drag with the editor is the only way I know.
While it’s nice to be able to click and drag stuff on the code, sometimes it’d really help me to be able to do it with code.

For example, not long ago I was making a vertex based animation system, each frame was a mesh, but I found no way to access the frames from within the code, I had to drag frame by frame, and each animation was 30 frames, I had no choice but to put that project on hold until I found a way to do this!

Id like to know this too.

You can use the Resources.Load function as described in the docs. Note that your prefab directory needs to be placed somewhere within a folder called ‘Resources’ for this to work.

The huge drawback of this approach is that any resources in that folder are always included in all your scenes, as Unity cannot know when you will access them. This means you will have to keep tracks of prefabs that are no longer used and remove them from the folder, or they will still be included in the build.

Alternatively, you could parent all the Prefabs of a specific folder to an Empty GO and attach this code to it:

var prefabArray : Transform[];

function Start(){
        var totalPrefabs = 0;
	for (var prefab : Transform in transform) {
		totalPrefabs++;
	}
        prefabArray = new Transform[totalPrefabs];

        prefabIndex = 0;
	for (var prefab : Transform in transform) {
                prefabArray[prefabIndex] = prefab;
		prefabIndex++;
	}

}

There might be a way to optimize this code more, but it should work non-the-less. =) Good luck!