- Home /
Question by
Kolalamonkeys · Aug 18, 2020 at 07:57 PM ·
instantiatechildrencolor change
Change color of children separately
I need to change each of the four children's colors separately. This should happen when the object is instantiated. Right now I have:
foreach (Transform child in Children)
{
child.gameObject.GetComponent<MeshRenderer>().material = red;
}
Which isn't working at all. I get an error that the parent doesn't have a mesh renderer, but I'm just trying to change the color of the children. Please help my simple mind figure out the problem! Thanks in advance!!
-Edit-
By adding a mesh renderer to the parent, all children change materials. I still need to change them separately, though.
Comment
child.gameObject.AddComponent<$$anonymous$$eshRenderer>();
Answer by myzzie · Aug 18, 2020 at 08:49 PM
Without knowing what Children is. Make sure it's the transform of the parent.