A question about newAttacker.transform.parent = transform;

I struggle a bit understanding newAttacker.transform.parent = transform;
Should I understand it as that in the transform of the newAttacker there is a variable parent. And In this sentence we make a reference to the transform of the gameobject that the script is attached to here Spawner .
Whit other words we make a reference to the Spawners transform and put it in the variable parent in the newAttackers transform. Then the newAttacker knows to it´s parent Spawner or what??

1 Like

Ok so as you may know all gameobjects have a transform property . And transforms have a parent property.

newAttacker => some gameobject
.transform => the gameobject’s (newattacker’s) transform
.parent => the transform that this (newattacker’s) transform is the child of or should become the child of

So in the image below SomeGameobject transform is the parent transform of AnotherGameobject’s transform. In the editor we can do this for eg. by dragging one gameobject into a existing one .
image

The same thing can be done programmatically by setting the transform of one gameobject as the parent tranform of another game object’s transform . So the transform after the equal sign will be set as the parent transform of the newattacker transform.

newAttacker.transform.parent = transform

1 Like

Thanks for your good response. It´s make it more clear for me :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms