title: Manipulate Material Elements of Child Object
body: <p>I have a set of 3D models and each has its own material elements. One model has all elements in a mesh renderer and its easy for me to make changes to each elements as seen below:</p>
  
  <p><a href="https://i.stack.imgur.com/TL3mx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TL3mx.png" alt="enter image description here"></a></p>
  
  <p>Code used to make changes</p>
  
  <pre><code>public Renderer[] rend;
  
      rend[PlayerPrefs.GetInt("SelectedBall")].materials[0].color = currentcolor;
      if (PlayerPrefs.GetInt("SelectedBall") == 1)
      {
          rend[PlayerPrefs.GetInt("SelectedBall")].materials[0].color = Color.white;
          rend[PlayerPrefs.GetInt("SelectedBall")].materials[1].color = currentcolor;
          rend[PlayerPrefs.GetInt("SelectedBall")].materials[2].color = currentcolor;
          rend[PlayerPrefs.GetInt("SelectedBall")].materials[3].color = currentcolor;
      }
  </code></pre>
  
  <p>I have a second model with 2 child objects, each with its own elements.</p>
  
  <p><a href="https://i.stack.imgur.com/VPqvV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VPqvV.png" alt="enter image description here"></a></p>
  
  <p>The challenge I am facing is if I use same code above, it only affects "Cylinder001" elements.</p>
  
  <p>How do I access the Sphere003 elements and make changes as well in one code.</p>
  
  <p>Thanks</p>