Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Lock a GameObject Child

Discussion in 'Scripting' started by Hannibal11, Jan 20, 2021.

  1. Hannibal11

    Hannibal11

    Joined:
    Mar 5, 2020
    Posts:
    15
    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
     

    Attached Files:

  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Are you trying to do this in the editor or during gameplay?
     
    Hannibal11 likes this.
  3. Hannibal11

    Hannibal11

    Joined:
    Mar 5, 2020
    Posts:
    15
    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?
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    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.
     
    Hannibal11 likes this.
  5. Hannibal11

    Hannibal11

    Joined:
    Mar 5, 2020
    Posts:
    15
    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?
     
  6. seejayjames

    seejayjames

    Joined:
    Jan 28, 2013
    Posts:
    685
    Hannibal11 likes this.