I want to replace a child gameobject by an another one at the same level of hierachy.
I tried to copy the transform.parent value of the original object before instanciate a new one and copy the transform on it then destroy the primary child object. But it doesnt work.
The instanciate object is not instanciate as a child and i got a MissingReferenceExeption because i try to access a destroyed object.
here is my code :
using UnityEngine;
using System.Collections;
public class EditorManager : MonoBehaviour {
void StartPlaceObjs () {
GameObject mybutton;
GameObject myref;
myref=GameObject.Find("Button_Objects");
mybutton=EditorData.editorPrefabs[7];
mybutton.transform.parent = myref.transform.parent;
GameObject.Instantiate(mybutton);
GameObject.DestroyImmediate(myref);
}
}