- Home /
How to get all child objects under specific object ?
I have a empty GameObject under it i have another gameobject name: Propellers under it i have 4 gameobjects name: "Propeller1" , "Propeller2" , "Propeller3" , "Propeller4"
I want to get this 4 gameobjects that are under Propellers that is under the main parent object.
private void Start()
{
var Object = GameObject.FindGameObjectWithTag("Propellers");
allObjects = new List<GameObject>();
var t = Object.GetComponent<Transform>();
foreach(Transform t in transform)
{
}
}
I want to add the 4 properllers to allObjects.
Answer by ShadyProductions · Jul 25, 2017 at 08:07 AM
https://docs.unity3d.com/ScriptReference/GameObject.GetComponentInChildren.html
var childrenTransforms = gameObject.GetComponentInChildren<Transform>();
Do some research on the wiki first please.
var childrenTransforms = gameObject.GetComponen**s**tInChildren<Transform>();
is the correct one
Your answer
Follow this Question
Related Questions
Why when creating new animator controller for the character the character is not walking right ? 0 Answers
How can i Instantiate on the terrain from left to right ? 0 Answers
Why the tile map scripts take almost all the cpu usage ? cpu usage is getting to 99% at times 1 Answer
How can i rotate object by pressing on key R and keep object facing to me my self ? 0 Answers
How can i spawn new gameobjects to be inside the terrain area ? 2 Answers