Search Unity

Acces to a child object

Discussion in 'Getting Started' started by Stradmann, Jun 11, 2018.

  1. Stradmann

    Stradmann

    Joined:
    Jun 11, 2018
    Posts:
    38
    Hi. Sorry about my english..
    I've two GameObjects, "Unit" and "UnitDestination". "UnitDestination is a child of "Unit". I want to acces to "UnitDestination" transform from a script attached to "Unit" gameobject. I tried this:
    Code (csharp):
    1.  
    2. private Transform destination;
    3.  
    4.     void Awake()
    5.     {
    6.         destination = GetComponentInChildren<Transform> ();
    7.         Debug.Log (destination.name);
    8.     }
    9.  
    but console debugs "Unit", not "UnitDestination". I don't understand why doesn't work.. any help?
     
  2. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    814
    AlanMattano likes this.
  3. Stradmann

    Stradmann

    Joined:
    Jun 11, 2018
    Posts:
    38
    Thank you!!