Hi guys,

I’m tryng to select a material colour for an array ive set up, however i cant work out how to get it working without errors, what am i doing wrong?

	void Start() { string[] colours = {"green", "red", "white", "blue"};
		

		//foreach(string i in colours)
		//print(i);

		int thename = colours.Length;
		int rndColour = Random.Range(0, thename);
		print(rndColour);


		gameObject.GetComponent<Renderer>().material.Color = colours[rndColour];

}

No you have to take array of Color type not String type as following.

void Start() { 
		Color[] colors = {Color.green,Color.red, Color.white, Color.blue};
		 		
		int lengthOfColors = colors.Length;  //Isn't this is better name than thename?
		int rndColor = UnityEngine.Random.Range (0, lengthOfColors);
	
		gameObject.GetComponent<Renderer>().material.color = colors[rndColor]; //note the small 'c' in material.color

	}