- Home /
Making a object a child of another
I have had a look at other questions but none of them helped me...
I have a player and I have a simple inventory and when you click on a weapon to equip, it creates the weapon where it should be, but the object would become a child of the player hand. I have tried "childObject.transform.parent = parentObject.transform" it wouldn't work
Every time the object gets created a warning pops up saying: "Setting a parent of a transform which resides in a prefab is disabled to prevent data corruption" I have tried it with both my player and my weapon not being a prefab and it still wouldn't work
How can this be fixed? (Im using JavaScript)
Answer by cowasockytommy · Apr 19, 2013 at 10:06 AM
transform.weapon.parent = transform.hand;
i think this is what your looking for
that helped but now there is another warning that says:
"Object reference not set to an instance of an object"
that's b/c something in the inspector isn't assigned right..recheck the inspector and re assign your weapons and what not
click on the warning and you'll see in the hierarchy a object light up click it and re-assign w/e is in the object
I got it I just had to do:
transform.weapon.parent = GameObject.FindGameObjectWithTag ("Hand").transform;
Thanks for the help mate