There seem to be a lot of question concerning this and while some of them seem to have working solutions, they do not work in my project no matter what I do.
An elevator platform should spawn a prefab model when function MakePillar is called.
This model should then be parented to the platform. All code is included in the Elevator's script, so no third objects are involved.
var PillarPrefab : GameObject; // The Pillar model that appears below the elevator platform. The function gets called in the Update function when a key is pressed.
function MakePillar()
{
var Pillar : GameObject = Instantiate(PillarPrefab, transform.position, transform.rotation ) ;
Pillar.transform.parent = transform ;
}
What works: The first part, i.e. creating the pillar at the correct position.
What doesn't work: the second part, i.e. parenting the new clone to it's parent, the elevator.
I already read and tested the code from the following threads...
http://answers.unity3d.com/questions/428578/parenting-an-instantiated-prefab.html
http://answers.unity3d.com/questions/55796/instantiate-a-prefab-to-a-parent.html
http://answers.unity3d.com/questions/428578/parenting-an-instantiated-prefab.html
↧