Hi the following code is throwing a null exception. There is no space in naming the Quad. The name is exactly what the code is trying to find.
MeshRenderer mesh = transform.Find("Top").GetComponent<MeshRenderer>();
mesh.material.color = color;
But when I change to this code, its working. How is the above code working for Ben?
private void SetTopColor(Color color)
{
// MeshRenderer mesh = transform.Find("Top").GetComponent<MeshRenderer>();
// mesh.material.color = color;
Transform[] childTransforms = GetComponentsInChildren<Transform>();
foreach(Transform childTransform in childTransforms)
{
MeshRenderer mesh = childTransform.GetComponent<MeshRenderer>(); ;
if (childTransform.name.Equals("Top") && mesh.material.color!=color)
{
mesh.material.color = color;
}
}
}