title: How to dynamically set a random Material on a GameObject
body: <p>I'm a total newcomer to unity and I was just wondering how to set a material from C#?</p>
  
  <p>I have a prefab model and I can change the texture from the editor no problem.  What I want to do is randomly set the material when an instance of the prefab is generated.</p>
  
  <p>Here is the field I want to change:</p>
  
  <p><a href="https://i.stack.imgur.com/5zt9D.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5zt9D.png" alt="Unity Field"></a></p>
  
  <p>And I am creating these with the following code:</p>
  
  <pre><code>Instantiate(eggPrefab, spawnPos, Quaternion.identity);
  </code></pre>
  
  <p>(Where eggPrefab is a public Transform).</p>
  
  <p>I hope that is enough information!</p>
  
  <p>Thank you.</p>