- Home /
Check if there is a child of object, and if so, get tag?
Hi, im making a game with guns and i want to make an animation for both walking and idle for when theres no gun, a one handed gun, and a 2 handed gun.
however, im not sure how to get the children's tag? how can i get the children and check the tags?
Answer by InvincibleCat · Feb 13, 2015 at 06:06 PM
foreach (Transform iChild in transform)
{
string tag = iChild.gameObject.tag;
}
Here you go. That one will work.
It is just a way to name stuff. i just says that in an iterator variable. So for example you can't remove it while your are iterating
Answer by steakpinball · Feb 13, 2015 at 03:56 PM
Start by checking how many children there are with Transform.childCount. Then iterate with a loop over each child checking the tag.
var childCount = transform.childCount;
for (var i = 0; i < childCount; ++i) {
var child = transform.GetChild(i);
var childTag = child.tag;
// Do something based on tag
}
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Orient parent to child location 2 Answers
Parent weapon to hand bone 2 Answers
Find children by tag from Player 1 Answer
Access a child from the parent or other gameObject. 2 Answers