title: Set the color of an object in unity
body: <p>I am trying to generate randomly colored trees in Unity in C#. The Line of Code I have is:</p>
  
  <pre><code>stemObject.GetComponent&lt;Renderer&gt;().material.color = StemCol;
  </code></pre>
  
  <p>It will the first time color it pink or light blue (though it is not the specified color), and when restarting the script always white, until the script is executed once without the line.</p>
  
  <p>Without the line there is a very normal shading.</p>
  
  <p>I also tried this</p>
  
  <pre><code>Color[] cols= new Color[m.vertices.Length];
  for (int i = 0; i &lt; m.vertices.Length; i++) {
      cols[i] = StemCol;
  }
  stemObject.GetComponent&lt;MeshFilter&gt;().mesh.colors = cols;
  </code></pre>
  
  <p>but it didn't have any effect at all.</p>
  
  <p>How do I change the color of the object without the weird shading, and in the right color?
  <img src="https://i.stack.imgur.com/nh5kL.jpg" alt="shading without the script">
  <img src="https://i.stack.imgur.com/X2mOh.png" alt="pink shading - though not the selected color">
  <img src="https://i.stack.imgur.com/MoSkF.png" alt="WHITE BUG"></p>