title: How can i add a renderer to gameobject in script?
body: <pre><code>GameObject cube = Cube.CreatePrimitive(Cube.CubePivotPoint.UPLEFT);
  cube.GetComponent&lt;Renderer&gt;().material.color = Color.blue;
  </code></pre>
  
  <p>When i assign the color i'm getting exception on the line:</p>
  
  <pre><code>cube.GetComponent&lt;Renderer&gt;().material.color = Color.blue;
  </code></pre>
  
  <blockquote>
    <p>MissingComponentException: There is no 'Renderer' attached to the "CubeHolder" game object, but a script is trying to access it.
    You probably need to add a Renderer to the game object "CubeHolder". Or your script needs to check if the component is attached before using it.</p>
  </blockquote>
  
  <p><strong>NOTE</strong>:</p>
  
  <p>I am using the <code>CUBE</code> class from <a href="https://stackoverflow.com/a/43036690/3785314">this</a> answer to create a cube, not the Unity's <code>GameObject.CreatePrimitive</code> function. </p>