- Home /
How to parent these multiple objects to othe multiple objects?
I cant get it right, tried many things but none worked.
Code:
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[i].position, ds.wFx[i].rotation);
}
}
Answer by DeadKenny · Dec 09, 2013 at 12:42 PM
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[i].position, ds.wFx[i].rotation) as ParticleEmitter;
ptc.transform.parent = ds.wFx[i].transform;
Answer by Guts · Dec 09, 2013 at 01:36 AM
First you need to store the reference returned by Instantiate:
GameObject child = Instantiate(groundTrailParticle, ds.wFx[i].position, ds.wFx[i].rotation) as GameObject;
Then set the parent by assigning to transform.parent (here I'm assuming you want ds.wFx[i] to be the parent, change if that's incorrect):
child.transform.parent = ds.wFx[i].transform;
Your answer
Follow this Question
Related Questions
C#: Particle Prefab doesn't follow it's parent (sort of) 0 Answers
Detach a child that has children 1 Answer
If A collide with B A will become Child of B - C# 3 Answers
remove parent of particles while emiting? 0 Answers
First child of a gameobject 3 Answers