- Home /
The question is answered, right answer was accepted
Assign parent object to target
I have an object that flies around the screen, rotating randomly. I need another object that stays way above it, without rotating. The script on the child object just moves to target.position.x and y, and maintains the original rotation. It does exactly what I want, only I have to drag the parent into the inspector, and I have nearly a hundred of these objects in my scene, which would take for ever. You're already thinking, "why doesn't this idiot use a prefab?" Just believe me what I say that I'm in a unique situation and that isn't an option, and it would take a long time to describe it.
That being said, I should be able to just assign the object's parent to the target variable via script, right?
Answer by phil_me_up · Apr 04, 2016 at 11:34 PM
If you're asking for a way to make one gameObject a child of another, use SetParent: http://docs.unity3d.com/ScriptReference/Transform.SetParent.html
The child object is already the child object...There is a transform variable on the child object script. I want to assign the child's parent to that transform via script.
Follow this Question
Related Questions
Make a simple tree 1 Answer
Kinematic Child Object Jumping Above Player 1 Answer
iOS Instantiate transform as child -- positioning bug 2 Answers
How Do I Offset a Childs Transform? 3 Answers