﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;

[ExecuteInEditMode]
public class SetAsLastScript : MonoBehaviour {
	[HideInInspector]
	public List<Transform> myChildren;

	void Update () {
		transform.SetAsLastSibling ();
		foreach (Transform t in transform) {
			bool belongsHere = false;
			for (int i = 0; i < myChildren.Count; i++) {
				if (t == myChildren [i]) {
					belongsHere = true;
					break;
				}
			}
			if (!belongsHere) {
				t.parent = null;
			}
		}
	}
}
#endif
