Renaming Child Objects during Instantiate?

When Instantiating an object, how do you rename the child objects within the gameobject (parent) that is being instantiated?

Basically I have this:

  • MainObject
  • ChildA
  • ChildB

When I instantiate and use name to rename the obect, it renames the parent object, like this:

  • MainObject_DifferentName
  • ChildA
  • ChildB

But I want to do something like this:

  • MainObject
  • ChildA_2
  • ChildB_2

I think you will need to get the children of the instantiated object. Maybe something like this?

instantiatedObject.name = "MainObject";
for(var child : GameObject in instantiatedObject) {
     if(child.name != "MainObject");
          child.name = child.name+"_2";
}