Change color of all material in all renderers

I want to change the color of all the materials in a single gameobject to blue or red but right now it won’t change the pillow’s color.

69687-sofathatisnotred.png

69688-sofarenderer.png

Here’s the code that I am currently using. When player middlemouse clicks it detects whether it hit a movable object then gets it’s renderer then opens a color canvas with different colors in it. When player clicks on the red color I want to change the whole sofa to red, including the pillows.

 private GameObject furniture;
    public GameObject ColorMenu;
    private bool canvasisopen;
    public Texture[] textures;
    public Renderer[] rend;
    private Material[] materials;
    private Color[] colors;
	// Use this for initialization
    void Awake()
    {
        canvasisopen = false;
        
    }
	void Start () {
         
	}
	
	// Update is called once per frame
	void Update () {
        
        if (Input.GetMouseButtonDown(2))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            Physics.Raycast(ray, out hit);
            furniture = hit.transform.gameObject;
            rend = furniture.GetComponentsInChildren<Renderer>();
            

            if (furniture.tag == "GroundFurniture" || furniture.tag=="WallArea" && canvasisopen == false)
            {
                
                Debug.Log(furniture.name);
                ColorMenu.SetActive(true);
                canvasisopen = true;
            }
            else if (canvasisopen == true && Input.GetMouseButtonDown(2))
            {
                canvasisopen = false;
                ColorMenu.SetActive(false);
            }
        }
    }



    public void ChangeToRed()
    {
        for (int i = 0; i < rend.Length; i++)
        {
            
                rend_.materials*.color = Color.red;*_

}
}

Figured it out. For anyone having the same problem, you need to getcomponentsinchildren all the renderers then use a for loop to get the materials and store within a material array. Use another for loop to cycle through the materials and assign each material the color you want.

Note that you need a renderer array and a material array.

public void ChangeToRed()
    {
        for (int i = 0; i < rend.Length; i++)
        {
           materials = rend*.materials;*

}
for (int z = 0; z < materials.Length; z++)
{
materials[z].color = Color.red;
}
}