Unity 別のレイヤーに追加したオブジェクトを元の位置に戻す
よくあるチュートリアルなどで黒背景にUIを追加して前面に表示させたい場合等。
Canvas以下で管理するオブジェクト(uGUI関連)は子の順序で描画順が決まるので
インデックス値を一度保存しておく必要がある。
環境
Unity 5.3.5f1
// 前面に表示 Transform parent= transform.parent; int index = transform.GetSiblingIndex(); transform.SetParent(target.transform); // 元に戻す transform.SetParent(parent); transform.SetSiblingIndex(index);