title: In Unity, how to access children component of the prefab using script?
body: <p>Prefab hierarchy:</p>
  
  <blockquote>
    <p>Button</p>
    
    <blockquote>
      <p>1 Text</p>
      
      <p>2 Image</p>
    </blockquote>
  </blockquote>
  
  <p>I wish to access Image child component of the prefab.</p>
  
  <p>I tried the following code:</p>
  
  <pre><code>GameObject addTypeButton = (GameObject)Instantiate(prefabButton);
  addTypeButton.transform.SetParent(ParentPanel, false);
  //set text
  addTypeButton.GetComponentInChildren&lt;Text&gt;().text ="Some string";
  //get image
  WWW www = new WWW("someImagelink");
  yield return www;
  //set image
  addTypeButton.GetComponentInChildren&lt;Image&gt;().sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width,www.texture.height), new Vector2(0, 0));
  </code></pre>
  
  <p>However, the above code is accessing Image script of Button (inbuilt).
  Not the Image UI component.
  How do I access UI Image (child) component?</p>
  
  <p>Please help.</p>
  
  <p>Thanks!</p>