- Home /
Question by
hardmode2236 · May 15, 2014 at 04:25 AM ·
transformarraygetcomponentsinchildren
trouble getting all children into an array.
I'm trying to get all the children of an object into a Transform[] variable like so:
#pragma strict
var tiles:Transform[];
function Start ()
{
tiles = gameObject.GetComponentsInChildren(Transform) as Transform[];
}
I'm not sure about the "as Transform[];" bit, but I get a warning about implicit downcasting from component to transform if I don't have that in there.
anyway, I don't get any errors but when I run that, nothing happens, and I don't know why.
Comment
Best Answer
Answer by fafase · May 15, 2014 at 04:58 AM
The transform of your object already contains all it's children in an array
foreach(Transform t in transform )
This will get you the child transforms.
Your answer
Follow this Question
Related Questions
Nested Prefab Issue 0 Answers
Unity3D - Playback object array of position (with dynamic velocity) 0 Answers
Getting radius around multiple transform 1 Answer
What is wrong with this code? 0 Answers