I would like to set programatically the material on a Game Object. The problem is that it has several Child Objects, which many have their own sprite.
I came up with this...
foreach(Transform child in enemy.transform) {
SpriteRenderer _spriteRenderer = child.GetComponent<SpriteRenderer>();
if (_spriteRenderer) {
_spriteRenderer.material = ...;
}
}
...which works, but it is not very pretty. Is there a better way to do this?
Update: I know about GetComponentsInChildren
but I need to also get the GameObject that are disabled