How do you assign a material to multiple different objects using arrays?

Hey there,

In my unity project I’ve got an array of 16 gameobjects and an array of 16 bools. I would like to make a function that when called will check the bools and give all false bools a purple material and all true bools a blue material.

This means that if I would set the first bool of the bool array to false and then call the function, the material of the first gameobject would be set to purple, but if the first bool would be true, the material of the first gameobject should be blue. And so on for all 16 gameobjects of the array.

Does someone know how to do this? (I’m kinda new to C# and arrays)

if it was about only to colors this function is good . if not then script should be extended so let me know.

public GameObject[] obj;
public bool[] cheek;
Renderer rn;

 void Change(){
	for (int i = 0; i < obj.Length; i++) {
		rn = obj*.GetComponent<Renderer> ();*

_ if (cheek ) {_
* rn.material.color =;*
* } else {*
* rn.material.color = Color.magenta;*
* }*
* }*
* }*