|
Basically this: On a prefab, needs to tag all the children in the prefab with that tag, without knowing their names specifically. Is it possible?
(comments are locked)
|
|
Not tested, but this should work (C#): Won't work on deep hierarchies- Transform[] only works on the layer directly below, it doesn't work recursively. Try using GetComponentsInChilderen<.Transform>() (without the . infront of the Transform (silly html tags having the same format as generics)) - this returns an array of all the transforms below the current transform.
Sep 18 '11 at 04:36 AM
syclamoth
Thanks, feel like I've learned something from this. Would be nice if layers and tags were components eh? Here's the final JS: for (var child : Transform in transform) { child.tag = "theTag"; }
Sep 19 '11 at 08:21 AM
hawken
I had the same issue and found it doesn't help when going past the first level of children. What I ended up doing was a recursive loop to solve the issue. C# void OnDrawGizmosSelected () { ReTag(transform, transform.tag); } void ReTag (Transform _transform, string tag) { foreach(Transform child in _transform){ child.gameObject.tag = tag; ReTag(child, tag); } } Thought I would post for anyone else that might need it.
Sep 25 '11 at 03:36 AM
Adamcbrz
(comments are locked)
|
|
You can easily achieve that with a recursive method:
(comments are locked)
|
|
Thanks for this, I'll check if it works. My initial feeling is that you can't access grandchildren with GetComponents, because Unity throws an error as tags are not components...? No, you use GetComponents, and then for each component returned use to fix up the tag! No, tags are not components, but it is possible to access the tag of any object with just a reference to one component on that object.
Sep 19 '11 at 08:26 AM
syclamoth
(comments are locked)
|
