Quantcast
Viewing all articles
Browse latest Browse all 508

how to break connection between gameobject and its clone in unity.

Hi, i have boxes gameobject and its children. Before i rotate or move this object, i insantiate all of them with using Record() method and if user want to take back action with using Undo() method, all objects including its clones is destroyed, so i dont want to destroy clone objects. how to break connection between gameobject and its clone. Sorry for my english thanks in advance. Here is the code public Gameobject boxes, boxesCopy; public void Record(){ if (boxesCopy != null) { Destroy (boxesCopy); } boxesCopy=Instantiate(boxes); boxesCopy.SetActive (false); } public void Undo(){ Transform[] realChildren = boxes.GetComponentsInChildren(); foreach (Transform child in realChildren) { Destroy (child.gameObject); } Transform[] copyChildren = boxesCopy.GetComponentsInChildren(); foreach (Transform child in copyChildren) { child.transform.parent = boxes.transform; child.SetActive (true); } }

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>