- Home /
How do i make my bulletSpawn become a parent of something
bulletSpawn = transform.Find ("bulletSpawn");
How do i make my bulletSpawn become a parent of something
Answer by BiG · Jun 14, 2013 at 08:00 AM
Transform.parent does the trick. The documentation provides an example, so it shouldn't be difficult to adapt it to your situation.
Answer by DavidDebnar · Jun 14, 2013 at 08:43 AM
You need to use Transform.parent.
var parent : Transform;
var bulletSpawn : Transform;
function Start () {
bulletSpawn = transform.Find("bulletSpawn");
bulletSpawn.parent = parent;
}
Edit: Thanks to schnaddlbraag for pointing out that the above example makes the bulletSpawn a child of the parent object. If you want to do the reverse, use
var child : Transform;
var bulletSpawn : Transform;
function Start () {
bulletSpawn = transform.Find("bulletSpawn");
child.parent = bulletSpawn;
}
Be aware that noobme's original question was about making the bullet parent of something, not vice versa!
So Dávid Debnar's example (which is basically correct, of course), should probably goe something like this:
var newChild: Transform;
var bulletSpawn : Transform;
function Start () {
bulletSpawn = transform.Find("bulletSpawn");
newChild.parent = bulletSpawn;
}
Your answer
Follow this Question
Related Questions
finding an object with tag, out of a few objects that are in array 1 Answer
Picking up and dropping objects with parenting 1 Answer
local space and rotation issues 1 Answer
Can a Gameobject that is controlled by Animator be dragged by a non animator controlled object 1 Answer
check a object is parent or not? 1 Answer