hey guys,
i was wondering how can i tell an inactive game object to go to its original position and rotation when the game started.this inactive gameobject is a child of another object
the parent object moves around.the child when is active it also moves around and it can be unparented. so my question is how can i tell the child to move to the current position of parent and be placed exactly where i put at start point ? i think i need and empty game object in the scene as a manager to tell to the child when it is inactive it should go to the parent position.
how can i do that?
thanks
To access the gameObject when it’s inactive you can use GetChild().
So, first you create a variable to store the parent transform. Something like:
public Transform yourParentTransform;
and then whenever you want to reset your position, supousing your object is the first child, you use:
Transform yourDisableChildTransform = yourParentTransform.GetChild(0);
And you reset the object local position like this:
yourDisableChildTransform.localPosition = Vector3.zero;
Now your object will be place where the parent is.