How do I spawn an array of prefab clones as children of an object?

I’m currently using the following to spawn the “spawnClone” prefabs where they need to be and it is doing that just fine, however, I need them parented to “spawnLocations” and am unsure as to how.

using UnityEngine;
using System.Collections;

public class Structure_Spawner : MonoBehaviour {

	public Transform[] spawnLocations;
	public GameObject[] spawnPrefab;
	public GameObject[] spawnClone;


	void Start(){
		spawnSomething();
	}

	void spawnSomething(){
		spawnClone[0] = Instantiate(spawnPrefab[0], spawnLocations[0].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
		spawnClone[1] = Instantiate(spawnPrefab[1], spawnLocations[1].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
		spawnClone[2] = Instantiate(spawnPrefab[2], spawnLocations[2].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
		spawnClone[3] = Instantiate(spawnPrefab[3], spawnLocations[3].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
		spawnClone[4] = Instantiate(spawnPrefab[4], spawnLocations[4].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
		spawnClone[5] = Instantiate(spawnPrefab[5], spawnLocations[5].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
		spawnClone[6] = Instantiate(spawnPrefab[6], spawnLocations[6].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
		spawnClone[7] = Instantiate(spawnPrefab[7], spawnLocations[7].transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;
	}

}

@jordaneden

This is a simple system that does what you are looking for but using Lists instead of Arrays (more efficient)

I am sorry that I missed that.

See my updated code below

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Structure_Spawner : MonoBehaviour
{
    public int numberOfItemsToSpawn = 7; // modifiable in the inspector
    public List<Transform> spawnLocations = new List<Transform>();
    public List<GameObject> spawnPrefab = new List<GameObject>();
    public List<GameObject> spawnClone = new List<GameObject>();

    void Start()
    {
        for (int i = 0; i < numberOfItemsToSpawn; i++)
        {
            if ((i < spawnPrefab.Count) && (spawnPrefab *!= null) &&*

(i < spawnLocations.Count) && (spawnLocations != null))
{
if (spawnLocations*.parent != null)*
{
// this line spawns a prefab a an objects position
spawnClone = Instantiate(spawnPrefab_, spawnLocations*.parent.position, Quaternion.Euler(0, 0, 0)) as GameObject;*_

// this line makes the spawned prefab a child of the parent the prefab was spawned from
spawnClone_.transform.SetParent(spawnLocations*.parent, false);
}
}
else // this can else block can be removed
{*

if (i >= spawnPrefab.Count)
Debug.Log("spawnPrefab.Count = " + spawnPrefab.Count + " - Trying to spawn item number " + (i + 1)); // i is zero based
else if (spawnPrefab == null)
Debug.Log(“spawnPrefab[” + i “] is null”;_

if (i >= spawnLocations.Count)
Debug.Log("spawnLocations.Count = " + spawnLocations.Count + " - Trying to spawn item number " + (i + 1)); // i is zero based
else if (spawnLocations == null)
Debug.Log(“spawnLocations[” + i “] is null”;
}
}
}
}