I am trying to create a grid of tiles and basically have them all different colors(I have an array of 4 colors to choose from). I have been working on it for hours and looking online and nothing I do seems to make it change colors from the default prefab color.
I have a script that is creating the grid and the tiles. I have tried a few different ways(both are there, one is commented out) and it always stays the same color(it isn’t one in the array, it’s the default color of the prefab).
`void Start () {
//Set colors for tiles
colors[0] = new Color(242, 103, 103); //Pink
colors[1] = new Color(80, 206, 196); //Blue
colors[2] = new Color(147, 206, 80); //Green
colors[3] = new Color(238, 174, 79); //Orange
//Create the number of tiles needed
GameObject[] tiles = new GameObject[numRows * numColumns];
for (int i = 1; i <= tiles.Length; i++) {
tiles[i-1] = Instantiate(tilePrefab) as GameObject;
tiles[i-1].transform.SetParent(gameCanvas.transform);
tiles[i-1].transform.position = new Vector3 (x, y, 0f);
//tiles [i - 1].GetComponent<Renderer> ().material.color = colors [3];
Renderer rend = tiles[i-1].GetComponent<Renderer>();
rend.material.color = colors [3];
x += 320;
if (i % 3 == 0) {
x = 300;
y -= 320;
}
}`
Everything I find online does not work or is either outdated like renderer.material.color
edit: I apologize for the code being like that, it looks organized in the text box as I edit it, but when I save, it bunches it into a paragraph