How to assign different materials to different objects

I have 3 objects in my scene and 3 materials, what I would like is for every time i pick up object, all objects will have a random material based on the 3 materials. Like i picked up one object,so i want that my other items also changed color. I have this script so far,but only one item change color while i pick it up

public GameObject[] arrayofGameobjects;
public Material[] arrayofMaterials;
private MeshRenderer render;

private void Start()
{
    render = GetComponent<MeshRenderer>();
}


public void OnTriggerEnter(Collider other)
{
    foreach(GameObject _object in arrayofGameobjects)
    {
        render.material = arrayofMaterials[Random.Range(0, arrayofMaterials.Length)];
    }
}

Try checking the triggers, and put render.sharedMaterial, that’s a better practice, other than that I don’t see why it does not work.

try this

foreach(GameObject _object in arrayofGameobjects)
    {
        _object.GetComponent<MeshRenderer>().material = arrayofMaterials[Random.Range(0, arrayofMaterials.Length)];
    }