- Home /
Question by
Slat · Jul 29, 2011 at 05:01 PM ·
meshrenderergetcomponentsinchildren
Accessing all children and subchildren MeshRender Component
I'm trying to set all childrens MeshRenderer to false...what I am i doing wrong?
public static var child : Transform[] = null;
var g = new Gun();
g.weapon = Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.identity);
child = g.weapon.GetComponentsInChildren(typeof(Transform)) as Transform[];
for(var i : Transform in child){
Debug.Log("children : " + i.gameObject.name);
if(i.gameObject.GetComponent(MeshRenderer))
i.gameObject.GetComponent(MeshRenderer).enabled = false;
}
Comment
please edit your post, select all code and hit the 101001 button to format.
also, please edit your tags to separate the three words with ',' ins$$anonymous$$d of '-'!
Answer by SisterKy · Jul 29, 2011 at 07:30 PM
I would try something like this:
var allChildren = g.weapon.GetComponentsInChildren(Transform);
for (var child : Transform in allChildren) {
if(child.gameObject.GetComponent(MeshRenderer)){
child.gameObject.GetComponent(MeshRenderer).enabled = false;
}
}
Greetz, Ky.