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

93906-1.png

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

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.