Is there any way to get child list with tag, for example something like that (where Parent is object, from which one I’m trying to get child list with tag):
Parent.FindGameObjectsWithTag(“Child”);
Its not working, its just example from GameObject.FindGameObjectsWithTag(“Respawn”)); but I need something similar to it.
Need to get child list in array, that are tagged in one object.
you would probably want to use List for anything run-time, Array can be inflexible.
using System.Collections.Generic;
List<GameObject> gingers;
void ILikeGingers() {
//grab all the kids and only keep the ones with ginger tags
Transform[] allChildren = gameObject.GetComponentsInChildren<Transform>();
foreach (Transform child in allChildren) {
if (child.gameObject.tag == "Ginger") {
gingers.Add(child.gameObject);
}
}
}