- Home /
Question by
SavvaMadar · Oct 13, 2012 at 03:31 PM ·
javascript
Attach object as child using code
if(Hit.collider.tag == "Flesh"){var obj : Transform = Instantiate(BodyImpact,Hit.point,Quaternion.FromToRotation(Vector3.forward,Hit.normal)) as Transform;
}
My goal is to create object called BodyImpact on collision of an object with the tag called Flesh, this works but for some reason I can't get that BodyImpact object to become a child of the object hit... How do I do that? (JS)
Comment
Best Answer
Answer by MountDoomTeam · Oct 13, 2012 at 04:01 PM
BodyImpact.transform.parent =parent.transform;
It's as simple as that!
Instead of parent, use the game object that you have made that will be parent,free example bodyParent.
Almost works, this worked better for me though
var obj : Transform =
Instantiate(BodyImpact,Hit.point,Quaternion.FromToRotation(Vector3.forward,Hit.normal)) as Transform;
obj.transform.parent = Hit.collider.transform;