Get Childrens to new array from perents array.
Hi! I have public array, i will fill it with prafabs in inspector. Each prefab have 3 objects 2 with tags and they are childrens of third one. I need to get access to thouse with tags somehow. Preferably put them in two arrays.Can you help me with my problem ? BTW tagd objects one is GameObject(mesh) other one is a pointLight.
Answer by Geometrical · Oct 10, 2016 at 01:57 AM
Here, I wrote a neat function for you to access the children of an object by their tag.
Transform GetChildWithTag(Transform parent, string tag) {
for (int i = 0; i < parent.childCount; i++) {
Transform child = parent.GetChild (i);
if (child.tag.Equals (tag, System.StringComparison.Ordinal)) {
return child;
}
}
return null;
}
Your answer
Follow this Question
Related Questions
How would you move from a array like from [2] to [3] or backwards like [2] to [1] 2 Answers
Why can't I find a GameObject with FindGameObjectsWithTag 2 Answers
Noob question about very simple array script 2 Answers
How can i place subjects in different positions? 0 Answers
Adding a Highscore to game 1 Answer