Created
September 8, 2021 22:43
-
-
Save SiarheiPilat/a5b95bc728afc322ec2c5069a4be7781 to your computer and use it in GitHub Desktop.
Sets layer on all transforms and children
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// taken from: https://forum.unity.com/threads/change-gameobject-layer-at-run-time-wont-apply-to-child.10091/ | |
// special thanks to: chadfranklin47 | |
public static class ExtensionMethods | |
{ | |
public static void SetLayerRecursively(this Transform parent, int layer) | |
{ | |
parent.gameObject.layer = layer; | |
for (int i = 0, count = parent.childCount; i < count; i++) | |
{ | |
parent.GetChild(i).SetLayerRecursively(layer); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment