title: How do I set a material to an gameobject in unity c# script?
body: <p>I am attempting to set a material to a game object in my game, I created the object in script so I dont have the option to set it manually through unity. All of this has to be in script etc. my code is</p>
  
  <pre><code>void Start()
  {
  
  
      GameObject cube2 = GameObject.CreatePrimitive(PrimitiveType.Cube);
      cube2.transform.position = new Vector3(12f, -3f, -82.5f);
  
  
  }
  </code></pre>
  
  <p>So I set the cube I created to "cube2". So aka what I am attempting to do is set it to red. I currently have a material created named red. Thank you.</p>