How to Spawn a Prefab at an already Spawned Prefab's that's from an array at their transform.position?

I’m trying to spawn prefabs on to other prefabs that have already been spawned from an array.

So, let’s say I spawned 10 prefabs from my array.

I now need to spawn a prefab at each and every one of the previously spawned prefabs position. This need to be done one at at a time.

How do I go about doing this?

I’m thinking that getting each spawned elements transform.position would be one way to go about it, but I don’t know how to get the transform.position for each spawned prefab’s respective element.

Maybe another way is to name each clone uniquely myPrefab1, myPrefab2, etc, etc. and then spawn the second prefab on top of them that way, but again, I do not know how to get each prefabs transform.position.

Here’s my code to give you an idea of what I’m trying to do:

		if (Input.GetMouseButtonUp(0)){
			if (i<whatEverYouFeelLike){
				stuffFromArray = Instantiate(stuffArray*, spawnPosition, transform.rotation) as GameObject;*
  •  		stuffFromArray.name = "stuffFromArray " +i.ToString();*
    
  •  		i++;*
    

}

  •  	}*
    
  •  if (Input.GetMouseButtonUp(0) && spawnSecondRound){*
    

// Spawn Second Round of Stuff Here

// Spawn Second Round of Stuff at the stuffFromArray.transform.position, separately and one at a time, each time the mouse button is clicked

// How?
}
Any help is really appreciated.
Thanks!

I’m not quite sure I completely understand what it is that you wan’t to do.

Anyway: You can get the first prefabs transform quite simply by calling

stuffFromArray = Instantiate(stuffArray*, spawnPosition, transform.rotation) as GameObject;*

debug.log("Prefab position: " + stuffFromArray.transform.ToString());
I’ll modify your script to do what I think you want it to do, but then again I’m not quite sure I understood you correctly:
if (Input.GetMouseButtonUp(0))
{

//(I just added these so I didn’t get any compiler errors)
//---------------------------------------------------------------------------------
int i = 10;
int whatEverYouFeelLike = 1;
GameObject[] stuffArray = new GameObject[5];
GameObject[] SecondSpawnstuffArray = new GameObject[5];
Vector3 spawnPosition = transform.position;
//---------------------------------------------------------------------------------

if (i < whatEverYouFeelLike)
{
//You don’t have to save “stuffFromArray” for any longer than this frame, and you only use it in this if statement. Therefor you can define it here, by putting “Gameobject” in front of it.
GameObject stuffFromArray = Instantiate(stuffArray*, spawnPosition, transform.rotation) as GameObject;*
stuffFromArray.name = "stuffFromArray " + i.ToString();

GameObject SecondSpawnStuffArray = Instantiate(SecondSpawnstuffArray*, stuffFromArray.transform.position, transform.rotation) as GameObject;*
SecondSpawnStuffArray.name = "SecondSpawnstuffFromArray " + i.ToString();
i++;
}
}
//You don’t actually need this, atleast not for what you have presented on the forum. If you need it for some other reason, you can simply save the transform to a private variable, and use it here.
/*
if (Input.GetMouseButtonUp(0) && spawnSecondRound)
{
// Spawn Second Round of Stuff Here
// Spawn Second Round of Stuff at the stuffFromArray.transform.position, separately and one at a time, each time the mouse button is clicked
// How?
}*/