Change Color of Material without Calling Component

I am trying to change the color of a material and have it affect ALL components without have to call every component.

I am currently using:
Renderer rend = GetComponent();
rend.material.shader = Shader.Find(“Standard”);
rend.material.SetColor (“_Color”, Color.black);

This is working well - However, I have about 100 components that all use the same material that needs to be changed on a button click.

Is there a way that I can set a global variable so I can change the color of all components using the material?

Hi @GMVRDev

if you are using the same material for all the 100 components, then if you change the material property, it will apply to all the 100 components.

you could make

public Material  mat;

OnButtonClick()
{
mat.color = Color.red;
}

Get the gameobjects which has that special component. After that change their color on start function.

For example:

void ChangeColor()
	{
		foreach (MyScript item in GameObject.FindObjectsOfType<MyScript>()) 
		{
			item.gameObject.GetComponent<MeshRenderer> ().material.color = Color.red;
		}
	}

just did this with cubes.