"All parents/childs/sibling" is somewhat vague. Perhaps you could rephrase to be more descriptive. Where do you want to start from? Which direction do you want to go? How far do you want to go? When searching down, would you rather go as deep as you can first, searching from one side of the tree to the other or row by row?
Parenting forms a tree.
Searching only this GameObject's parents (going up the tree):
var foo : Transform;
var current : Transform = transform;
while(current.parent) {
current = current.parent;
if(current.name == "foo") {
foo = current;
break;
}
}
Searching all immediate children (searching the next row of the tree can be achieved by Transform.Find:
var foo = transform.Find("foo");
To search from the highest parent (the top of the tree), you would need to get this root transform and do the above there like so:
var foo = transform.root.Find("foo");
This is more meaningful if you know the exact path which you would delimit with '/' and grandchildren will be searched.
To search only siblings, you would go up one parent and then check all of its children like so:
var foo : Transform;
if(transform.parent) foo = transform.parent.Find("foo");
It isn't as fast, but to search all children at every level, you would use Transform.GetComponentsInChildren like so:
var foo : Transform;
for(var child : Transform in transform.GetComponentsInChildren(Transform)) {
if(child.name == "foo") {
foo = child;
break;
}
}
Likewise, to search the entire tree with no knowledge of the relationships, you would do as above with the root:
var foo : Transform;
for(var child : Transform in transform.root.GetComponentsInChildren(Transform)) {
if(child.name == "foo") {
foo = child;
break;
}
}
Using GetComponentsInChildren uses Depth-First-Search. If you had wanted to do a Breadth-First-Search, you would have to write one like so:
var foo : Transform;
var queue : Array = new Array();
for(var child : Transform in transform) queue.push(child);
while(queue.length != 0) {
var current = queue.shift();
if(current.name == "foo") {
foo = current;
break;
}
for(var child : Transform in current) queue.push(child);
}