How to set lots of Instantiate prefab Gameobjects in the same parent?

I want to let be cubepivot0(Clone) as child of "長條圖"
I've tried some solution but it never worked
GameObject temp=Instantiate(cube, transform.position, transform.rotation) as GameObject;
temp.transform.SetParent(bar);
or
GameObject temp=Instantiate(cube,transform.position, transform.rotation) as GameObject;
temp.transform.parent=bar;
or
Instantiate(cube, transform.position, transform.rotation) ;
GameObject.Find("cubepivot0(Clone)").transform.SetParent( bar);
but it failed
Answer by AhsanNaeem · May 11, 2017 at 06:41 PM
Try this one:
[SerializeField] GameObject buttonPrefab;
[SerializeField] Transform pp;
GameObject button = (GameObject)Instantiate (buttonPrefab);
button.transform.parent = pp;
Here pp is the parent. Button is created from Prefab and it becomes child of pp.
If you want to create more GameObjects for the same parent you can do it in for loop like:
for (int j = 0; j < 10; j++) {
GameObject button = (GameObject)Instantiate (buttonPrefab);
button.GetComponentInChildren<Text> ().text = (j + 1).ToString ();
button.transform.parent = pp;
}
This method didn't work for me.....
SO I tried this code below here
for (int i = 0; i < num; i++)
{
Instantiate(cube, new Vector3(i,i,i), transform.rotation);
GameObject.Find("cubepivot0(Clone)").transform.SetParent(GameObject.Find("長條圖").transform);
GameObject.Find("cubepivot0(Clone)").transform.localPosition = new Vector3(-6 + (6 / (num - 1)) * (i),-3, 0);
GameObject.Find("cubepivot0(Clone)").transform.localScale = new Vector3(1, 0, 1);
}
And it works.....but ONLY for one clone Why can't all of them get in the same gameobject? 
If your parent is not declared as Transform then you can use:
button.transform.parent = pp.transform;
Your answer
Follow this Question
Related Questions
Destroy a prefab from another class 2 Answers
How to get the position of a new Instantiated prefab 0 Answers
Rotation of instantiated object 1 Answer
How can I in-script create gameobject from prefab? 2 Answers