- Home /
Question by
Yezen0Nizam · Dec 13, 2019 at 11:49 PM ·
tagtags
How do I find grandparents with a certain tag ?
I don't want the root grandparent itself , I want its first child (which has a different tag) and its children to be destroyed and the root grandparent to stay alive .
Comment
Best Answer
Answer by GanemVisk · Dec 14, 2019 at 02:16 AM
The root grandparent is obtained by transform.root
. Then you can loop through its children , check if they have the tag and Destroy them as needed.
Transform parent = transform.root;
foreach (Transform child in parent)
{
if (child.CompareTag(tag))
{
Destroy(child);
}
}
Your answer
Follow this Question
Related Questions
Did any one got and issue with finding tag in 5.5.1 or later 0 Answers
How do I check in user-defined tags using subversion? 1 Answer
Accessing all GameObjects with a certain tag 1 Answer
Object not surviving on load? 1 Answer
Swapping a tag for string not working, replacing a tag with a public string, help. 1 Answer