Hello, so I really need help with this one. How I move all child objects from “fem1” to “character” and keep stacks/sorting…
my script does it like this(3rd pic) and 2 pic is how it should be…
script:
#pragma strict
//This script must be attached to clothing or body and functions can be used by UI buttons
var selected : boolean;
private var newParent : GameObject;
private var parentOBJ : Transform;
function Start () {
newParent = GameObject.Find("character");
parentOBJ = transform.parent;
}
function Update () {
var renderers = GetComponentsInChildren(Renderer);
var transforms = GetComponentsInChildren(Transform);
if (selected)
{
gameObject.tag = "active";
for (var r : Renderer in renderers) { r.enabled = true; }
for (var child : Transform in transforms) { child.transform.parent = newParent.transform; }
}
else
{
gameObject.tag = "de_active";
for (var r : Renderer in renderers) { r.enabled = false; }
this.transform.parent = parentOBJ.transform;
}
}
function MAKE_OBJ_ACTIVE ()
{
selected = !selected;
}
You need to only change the top level gameobject’s parents. You can get only the top level objects by using the transform in a using statement (which is not very intuitive to me)
Like this: for(var child : Transform in parentOBJ.transform)
Thank you for reply I tested that script it moved parent object including all childrens. I mean I want to keep parent object, but exctract all children objects to object in hierarchy. Problem is if move whole package like this to newparent “character” pre-setup animations won’t work I think bone data and everything must be in root and in order. I’am very bad in explaining hope it makes sense.
I think this is one way to do it it’s pretty complex system… but it works. Critics?