Skip to content

Instantly share code, notes, and snippets.

@andykorth
Created March 20, 2015 18:14
Show Gist options
  • Save andykorth/375f9d699e33e71f6718 to your computer and use it in GitHub Desktop.
Save andykorth/375f9d699e33e71f6718 to your computer and use it in GitHub Desktop.
Move a parent to where the children are
[MenuItem("Selection/Center on first child", false, 301)]
static void Center() {
Object[] objs = Selection.GetFiltered(typeof(GameObject), SelectionMode.Editable | SelectionMode.ExcludePrefab);
foreach (GameObject go in objs){
Transform child = go.transform.GetChild(0);
Vector3 childPos = child.position;
Vector3 childChange = childPos - go.transform.position;
go.transform.position = child.position;
foreach (Transform chld in go.transform) {
chld.position -= childChange;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment