- Home /
send an inactive game object to its original position and rotation through another game object
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
Answer by calpolican · Jan 26, 2018 at 08:40 PM
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.
Your answer
Follow this Question
Related Questions
set gameobject for another script 0 Answers
About untity send messages with android? 0 Answers
how do i make it so objects wont share the same texture? 2 Answers
OUYA Iap with OnCollisionEnter 0 Answers