- Home /
array of childern
There is a way to do an array of object like to using Component.GetComponentsInChildren command?
I'm afraid that your question doesn't make a lot of sense. Nothing is preventing you from creating an array and filling it with anything you want. If you're not sure how to code arrays in Javascript (and Javascript-like languages, such as Unityscript), then please read the W3Schools documentation...
Answer by whydoidoit · Sep 24, 2012 at 09:43 PM
I think you are probably after an array of GameObjects which are the children of the current object?
If so then you have two choices - all of the children or the immediate children. Unforunately you didn't say what language you wanted it in...
C#
using System.Collections.Generic;
using System.Linq;
//Immediate children
var myChildren = transform.Cast<Transform>().Select(t=>t.gameObject).ToArray();
//All children, not including self
var allChildren = GetComponentsInChildren<Transform>().Except(new [] { transform }).Select(t=>t.gameObject).ToArray();
JS
import System.Linq;
...
var myChildren = transform.Cast.<Transform>().Select(function(t) { return t.gameObject; }).ToArray();
//All children not self
var allChildren = GetComponentsInChildren(Transform).Except([transform]).Select(function(t) { return t.gameObject;}).ToArray();
I apologize. I explained bad anyway you know. I'm not familiar with C. .. if you could have a JavaScript version would be better, otherwise does the same. Somehow I manage very well. Thanks for answer.
I always get the wrong language first and without the ability to compile right now am not totally convinced about that [transform] in the all children line... Let me know if it works.
Your answer
Follow this Question
Related Questions
List children with name in array? 3 Answers
Take array and waypoints from parent spawnner 2 Answers
How to load all vertices form multiple children of a game object in to one big array? 0 Answers
Find Child of GameObject from Array in Different Script 0 Answers
Filling an array with child vectors 2 Answers