Hello! So I’m trying to change the material on a quad to a random picture whenever I load up the game. I’m using a for loop to instantiate the quad’s so it would be great if I could make their materials random.
Yes I read the API and it wasn’t helping me with my specific circumstance which is why I was hoping someone here could point me in the right direction.
public Material[] mats;
void levelCreate()
{
Material mat = mats[Random.Range(0, mats.Length)];
if (easy == true)
{
GetComponent<Renderer>().material = mat;
for (int i = 0; i < 5; i++) //makes the columns in the 5 by 5 grid
{
for (int j = 0; j < 6; j++) //makes the rows in a 5 by 5 grid
{
Instantiate(prefab, new Vector3(j * 1.5f - 3, i * -1.5f + 3, 0), transform.rotation);
prefab.name = count.ToString();
count++;
gameStart = false;
}
}
}
}
Oh and I read the API from Unity - Scripting API: GameObject.GetComponent
Unity - Scripting API: Renderer.material and Unity - Scripting API: Random.Range