Set material of child object that entered the collider of another object.

Hi i need little help. I have this script:

Transform hex;
public Material Dirt;
public Renderer[] childColors;

public void Start()
{
    
}
void OnTriggerEnter(Collider other)
{
    
    
     if (other.gameObject.tag == "Grass")
     {
        
         //MeshRenderer childColors = other.GetComponentInChildren<MeshRenderer>();
         //hex = other.transform.GetChild(0).GetChild(0);
         foreach (Renderer color in childColors)
         {
             color.material = Dirt;
         }
     }
}

Hmm. At first blush, you really should not name a renderer ‘color’. It really throws People of who work with renderers and/or Colors.

The Problem in your code above is that your foreach code always looks at ‘childcolors’ array, but never updates it. So you are assigning the Dirt material to the renderers in childColors over and over again. From the (much too short) description of what you are trying to accomplish I guess you should access the renderers of the collider ‘other’

Yeah