change layer of child

Does anyone know how to access the layer of a child and dynamically change it?

The code I have right now only changes the parent, and not the child. It tags the children well enough, so I may single them out for layer change.

gameObject.tag = "myTag";

for (var child : Transform in transform) {
    child.tag = "myTag";
}

var moveLayer : GameObject;
moveLayer = gameObject.FindWithTag("myTag");
moveLayer.layer = 11;

I tried the following, but layers are not part of transform.

for (var childl : Transform in transform) {
    childl.layer = 11;
}

How would one access them?

To change the layer of a child transform’s gameObject, use

child.gameObject.layer = LayerMask.NameToLayer("WhateverYouCalledIt");

I should warn you, however, that iterating through a Transform like this only returns the first layer of children- it doesn’t give you any children that those children might have. If you want to change an entire hierarchy, you should write some kind of recursive function which can be called on any given Transform to change the layers all the way down, like this (apologies in advance for dodgy JS syntax- I usually use C#):

function ChangeLayersRecursively(var trans : Transform, var name : String)
{
    for (var child : Transform in trans)
    {
        child.gameObject.layer = LayerMask.NameToLayer(name);
        ChangeLayersRecursively(child, name);
    }
}

This will make a deep search of a Transform hierarchy and change every child in it instead of just the first layer.

Hello
simple way to change layer in all child

// obj is your GameObject change it with your
    foreach (Transform child in obj.GetComponentsInChildren<Transform>(true))  
     {
               child.gameObject.layer = LayerMask.NameToLayer ("Default");  // add any layer you want. 
     }

the comment of vitaly is wrong.
child.ChangeLayersRecursively(name);
the method ChangeLayersRecursively is not a member of the Transform object.
ChangeLayersRecursively(child, name); is better

This worked for me

foreach (var partChild in part.part.GetComponentsInChildren())
{
partChild.gameObject.layer = 13;//layer number here
},This worked fo me.

Do you have a working example of what you said ? When I said it was wrong, you replied it is not wrong, it uses extension Methods. I want to see a working example of your call “child.ChangeLayersRecursively(name)” within the foreach loop of your declared Method “ChangeLayersRecursively(this Transform trans, string name)”