OnTriggerStay for many object

Hi. I’m looking for a solution to my problem: I have in the scene object with collider and rigitbody and that obejct collide with the other one. I’m using function OnTriggerStay and i want to change material of every object which is touching my main object. How i can make it work not only for one object at the time but for all?

ex. script

	void OnTriggerEnter (Collider col)
	{
		
		
			col.renderer.material = someMaterial;
		
	}

You could store all the objects in a List or Array, loop through them and compare them in the OnTriggerStay function:

public List<GameObject> listOfObjects; // needs using directive 'System.Collections.Generic'

void Start()
{
   listOfObjects = new List<GameObject>();
   listOfObjects.AddRange(GameObject.FindGameObjectsWithTag(Choose a tag));
}

void OnTriggerStay(Collider c)
{
   foreach(GameObject go in listOfObjects)
   {
      if(go.transform == c.transform)
      {
         go.renderer.material = someMaterial;
      }
   }
}

Not sure. But I think in that first line, variable definition could instead read:

public List<GameObject> listOfObjects;

No brackets that first time.