How to change multiple objects color with button?

Hi,
I have 4 objects (chair1, chair2, chair3 and chair4).
Object appears one at a time by clicking each chair button.
With this source code, I can change chair1 color to red by clicking red button.
But I want to change chair2, chair3 or chair4 color to red by clicking same red button.
How to change source code for this?

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ColorRed : MonoBehaviour
{

    public void onClick()
    {
        GameObject Chair1 = GameObject.Find("Chair1");
  
       Chair1.GetComponent<Renderer>().sharedMaterial.color = Color.red;
 
    }

}

This is my solution. Let’s prepare two classes: DynamicColorObject and ColorChanger.
`

using UnityEngine;
using System.Collections.Generic;

public class DynamicColorObject : MonoBehaviour {
	public static List<GameObject> list = new List<GameObject>();

	void Start () {
		list.Add(gameObject);
	}

	void OnDestroy() {
		list.Remove(gameObject);
	}
}

`

using UnityEngine;

public class ColorChanger : MonoBehaviour {

	public void changeColor()
	{
		foreach (GameObject dynamicColorObject in DynamicColorObject.list)
			dynamicColorObject.GetComponent<Renderer>().sharedMaterial.color = Color.red;
	}
}

Now attach DynamicColorObject to all objects that should be able to change color. When your button call function ColorChanger.changeColor() all this objects will change.

Thank you. It run well in one scene.
But when I run it using scene transform, it doesn’t run.

One is

using UnityEngine;
    
    
     public class ColorChanger : MonoBehaviour {
    
        public void changeRed()
         {
             foreach (GameObject colorObject in ColorObject.list)
                 colorObject.GetComponent<Renderer>().sharedMaterial.color = Color.red;
         }
        public void changeWhite()
        {
            foreach (GameObject colorObject in ColorObject.list)
                colorObject.GetComponent<Renderer>().sharedMaterial.color = Color.white;
        }
        public void changeBlue()
        {
            foreach (GameObject colorObject in ColorObject.list)
                colorObject.GetComponent<Renderer>().sharedMaterial.color = Color.blue;
        }
        public void changeYellow()
        {
            foreach (GameObject colorObject in ColorObject.list)
                colorObject.GetComponent<Renderer>().sharedMaterial.color = Color.yellow;
        }
        public void changeBlack()
        {
            foreach (GameObject colorObject in ColorObject.list)
                colorObject.GetComponent<Renderer>().sharedMaterial.color = Color.black;
        }
     }

The other one is

using UnityEngine;
using System.Collections.Generic;
public class ColorObject : MonoBehaviour
{
    public static List<GameObject> list = new List<GameObject>();
    void Start()
    {
        list.Add(gameObject);
    }
}

And this is error.

MissingReferenceException: The object of type ‘GameObject’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.GameObject.GetComponent[Renderer] () (at C:/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineGameObjectBindings.gen.cs:38)
ColorChanger.changeRed () (at Assets/ColorChanger.cs:9)
UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:144)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:621)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:756)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269)
UnityEngine.EventSystems.EventSystem:Update()

How to solve this problem…?
Help me., :frowning:
@adriono