How to parent these multiple objects to othe multiple objects?

I cant get it right, tried many things but none worked.


void OnTriggerEnter(){

if(other.tag == “car”){

                CarController ds = other.GetComponent<CarController>();

   for(int i = 0; i < ds.wFx.Length; i++){

// How to make these children of the things they are instantiating at?

     Instantiate(groundTrailParticle, ds.wFx_.position, ds.wFx*.rotation);*_ 


First you need to store the reference returned by Instantiate:

GameObject child = Instantiate(groundTrailParticle, ds.wFx_.position, ds.wFx*.rotation) as GameObject;*_

Then set the parent by assigning to transform.parent (here I’m assuming you want ds.wFx to be the parent, change if that’s incorrect):
child.transform.parent = ds.wFx*.transform;*

Got it!

It seems like it was because I was trying to parent a ParticleEmitter.

It worked when I instantiated it as a ParticleEmitter then parent it. I’m not sure though lol, it could just been my incredible retard powers acting up again.

Thanks for help though. It helped.

  ParticleEmitter ptc = Instantiate(groundTrailParticle, ds.wFx_.position, ds.wFx*.rotation) as ParticleEmitter;*_

ptc.transform.parent = ds.wFx*.transform;*