'How can i reset positions of Prefab children's in unity 2d. children's are also prefabs
I have an object which is prefabs and that object contains further objects(assets) which are also prefabs. I want to Reset position of Parent object and Children object when level fails. however I am not able to reset position of children object by instantiating. I can instantiate parent object but can not instantiate children objects. when I reload the scene, Scene get reloaded with the object which was active when game started not with the object on which level failed.
Solution 1:[1]
for reset all children's transform you can get it by GetComponentsInChildren<> like this:
Transform[] childList=parentObj.GetComponentsInChildren<Transform>();
foreach(var i in childList)
{
i.localPosition = Vector3.zero;
}
you can call it after instantiating prefab or after restarting game.
another way is attach an script to each children of prefab and in awake or start function reset the position. if it should not rest by zero you can store your default transform and set it on awake or start function.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mahdi Po |
