Hi. How do I access components in all of the children? When I used GetComponentInChildren it only changed it in one of the children, but I want all 9 to be changed.
Cheers.
Hi. How do I access components in all of the children? When I used GetComponentInChildren it only changed it in one of the children, but I want all 9 to be changed.
Cheers.
This wasn’t tested, just an idea of iterating over comps in transform(gameObject.transform). Anyways you should be able to get the general idea i hope.
//unity script/javascript
for (var child : Transform in transform) {
for (var comp : Component in child.GetComponentsInChildren(Script)) {
comp.name = "blah";
}
}
// c#
foreach(Transform child in transform)
{
foreach(Component comp in child.GetComponentsInChildren<SomeScript>())
{
comp.tag = "blah";
}
}