Get all materials of parent and its children in an array except for few

Posted by Ishan7 under C# on 2/25/2021 | Points: 10 | Views : 1801 | Status : [Member] | Replies : 0
I am getting all materials from the parent and its children and storing it in an array. I want to however ignore few gameObjects from the list to be added. Can I add a string as the gameObject's name to be ignored so that except these gameObject, everything gets added?

Also, I cannot get all materials with GetComponent<Renderer> ().materials; it displays an error. I am only able to get single material of the gameObject with GetComponent<Renderer> ().material;. What is the problem here?

public Renderer[] allChildRenderers;
public Material[] allMaterials;
public string[] GameObjects_ToIgnore;

void Start () {

allChildRenderers = GetComponentsInChildren<Renderer> ();
allMaterials = new Material[allChildRenderers.Length];

for (int i = 0; i < allChildRenderers.Length; i++) {
allMaterials[i] = allChildRenderers[i].GetComponent<Renderer> ().materials;
}

}





Responses

(No response found.)

Login to post response