Having a bit of trouble with using GetComponentsInChildren.
private Material[] cachecolours;
void Start ()
{
//...
cachecolours = transform.GetComponentsInChildren<Material>();
}
void Update ()
{
foreach (Material colour in cachecolours)
{
colour.color = new Color(cs, cs, cs);
}
}
I want to change the colour of the materials of each child of my object but I keep getting these errors:
ArgumentException: GetComponent requires that the requested component ‘Material’ derives from MonoBehaviour or Component or is an interface.
and
NullReferenceException: Object reference not set to an instance of an object
I believe the second is due to the first but I can’t figure out how to change the colour of each child in turn.
cs is assigned a float value I just excluded that part of the code.