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

accesing child object

Discussion in 'Editor & General Support' started by verderveremem, Jun 17, 2014.

  1. verderveremem

    verderveremem

    Joined:
    May 11, 2014
    Posts:
    52
    Hi folks,

    how can i access to child object's position of a gameobject witout using "GameObject.Find"

    thanks
     
  2. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    Code (csharp):
    1.  gameObject.GetComponentInChildren<Transform>().position
     
    verderveremem likes this.
  3. verderveremem

    verderveremem

    Joined:
    May 11, 2014
    Posts:
    52
    thanks, can i use this code block in update method?
     
  4. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    Yes, but save gameObject.GetComponentInChildren<Transform>() to a variable in Start if possible, so that you don't call GetComponent in every Update call.