Instantiating prefabs to every object in an array?

Hey all,

I’m working on an office level, and I’ve opted to dynamically generate all of the decor for the cubicles. I’ve managed to get this working on a single cube, but now I’d like to expand it out to the rest using the same script. Here’s what I’ve got so far:

var computerLocation : Transform;
var computerPrefabs : GameObject[];
var plantLocation : Transform;
var plantPrefabs : GameObject[];


function Start() {

	GenerateDecor(); 
}


function GenerateDecor () {
Instantiate (computerPrefabs[Random.Range(0, computerPrefabs.Length)],computerLocation.transform.position, computerLocation.transform.rotation);
Instantiate (plantPrefabs[Random.Range(0, plantPrefabs.Length)],plantLocation.transform.position,Quaternion.identity);
}

Every cube will have the same collection of object types, so it seems I should just make my location variables arrays… But that’s where I become lost. I haven’t worked with arrays much, so I’m not sure how to tell the script to add a random prefab to each location in the proposed array.

If someone could point me in the right direction, I’d greatly appreciate it!

Did a bit more research and discussed my problem with a couple of other devs, and the now very obvious answer made its appearance: a for loop.

Derp! I feel silly now. Documenting in case someone else has the same quandary at some point:

function GenerateDecor(){
for(var i : int = 0; i < computerLocation.length; i++)
{
Instantiate (computerPrefabs[Random.Range(0,computerPrefabs.Length)], computerLocation_.position,computerLocation*.rotation);*_

}
}
Changed my location variables to arrays as I had thought I should, and that’s it. I’ll just go study more javascript now…