Lock a GameObject Child

Hello everyone.
I have a GameObject Parent (Cube), and a GameObject Child (Sphere).
If I select and move the Parent, the Child follows all of her movements, but if I select the Child it goes on her behalf.
I want the selection either of the Parent, or of the Child, to move together.
Is there a Specific Function in Unity to write via code?

Thank you all!

ps: Screen under


Are you trying to do this in the editor or during gameplay?

1 Like

Yes in gameplay … I want the user when clicking on it, to choose all the formation and not single elements. Is there any Unity function that does this? ps: In Sceene View is possible?

There’s no “unity function” that does it. Just parent all of the objects in the formation to a single shared parent object. When the player clicks any object in the group, simply move the parent object, rather than whatever individual child was clicked on.

1 Like

thank you so much for your help. I am a beginner, how do you share the same Gameobject parent?

In the Docs i find solution?

You can go up the Hierarchy with the “parent” property:
Unity - Scripting API: Transform.parent (unity3d.com)

1 Like