why setparent not working ?

public void generate_ball()
{
for(int i=0;i<balls_prefeb.Length;i++){

	GameObject	test =balls_prefeb[Random.Range(0,balls_prefeb.Length)] as GameObject ;
        Instantiate(test,this.transform.GetChild(i).transform.position,Quaternion.identity);
	           test.transform.parent = this.transform;
        
}

}

try this :

GameObject test = balls_prefeb[Random.Range(0,balls_prefeb.Length);] as GameObject ;
    GameObject testInstance=Instantiate(test,transform.GetChild(i).transform.position,Quaternion.identity);
                testInstance.transform.SetParent(transform);
         
 }

Like @efeguclu shows, when you pass a reference to the Instantiate method, it will return the instantiated object.

GameObject test = balls_prefeb[Random.Range(0,balls_prefeb.Length)] as GameObject ;

GameObject instance = (GameObject) Instantiate (test,this.transform.GetChild(i).transform.position,Quaternion.identity);

instance.transform.parent = this.transform;

Now, you can also pass a transform to the Instantiate method, and it’ll parent the instantiated object to it. Also, you don’t need to add “this” before transform, it’s implicit.

Instantiate (test, transform.GetChild(i).transform.position, Quaternion.identity, transform);