using System.Collections; using System.Collections.Generic; using UnityEngine; public class UIReorderer : MonoBehaviour { [Tooltip("The gameobjects get reordered accoring to this. Disable this cause no side effect.")] public GameObject[] order; [Tooltip("These are always lower then order[].")] public GameObject[] baseInsert; public bool destroyOnReordered; void Start () { for (var i = 0; i < order.Length; i++) { if (order[i] == null) continue; order[i].transform.SetParent(this.transform, true); order[i].transform.SetAsLastSibling(); } for (var i = 0; i < baseInsert.Length; i++) { if (baseInsert[i] == null) continue; baseInsert[i].transform.SetParent(this.transform, true); baseInsert[i].transform.SetAsFirstSibling(); } if (Application.isPlaying && destroyOnReordered) Destroy(this); } }