Can I change a material to effect all GameObjects with it?

Hello! I was simply wondering if the was a way to code a function that would change the material but not just on the single gameObject, I would like it to change all GameOjbects with the same material. So paste an example of the code or say something if it isn’t possible. (by the way I use JavaScript)

renderer.sharedMaterial

It does not matter which language you are using. Either make a reference to the material you want to change as a public variable and let your script change that, or you can access renderer.sharedMaterial on an object that has the material you want to change.

If you want to replace the material to a completely different material, access all renderers that has the material you want to change and replace it on all of them. You could use FindObjectsOfType to find all the renderers, then change the material of the renderers that has a common material.