- Home /
Question by
sicanothingelse · Apr 28, 2020 at 01:46 PM ·
parent-childparent transformparent and child
parent child object
How to make the plateObj the parent when it is instantiated and the nasiObj to be the child of the parent when instantiated ?
if (gameObject.name == "base_piring")
{
if (Gameplay.cuttingboardS1 == "empty")
{
Instantiate(plateObj, new Vector2(338.7f, 337.1f), plateObj.rotation);
Gameplay.cuttingboardS1 = "piring";
}
}
if (gameObject.name == "base_nasi")
{
if (Gameplay.cuttingboardS1 == "piring")
{
Instantiate(nasiObj, new Vector2(338, 339.7f), nasiObj.rotation);
Gameplay.cuttingboardS1 = "piringNasi";
}
}
,How can I make the plateObj to be the parent when instantiated and nasiObj to be the child whrn instantiated
if (gameObject.name == "base_piring")
{
if (Gameplay.cuttingboardS1 == "empty")
{
Instantiate(plateObj, new Vector2(338.7f, 337.1f), plateObj.rotation);
Gameplay.cuttingboardS1 = "piring";
}
}
if (gameObject.name == "base_nasi")
{
if (Gameplay.cuttingboardS1 == "piring")
{
Instantiate(nasiObj, new Vector2(338, 339.7f), nasiObj.rotation);
Gameplay.cuttingboardS1 = "piringNasi";
}
}
Comment
Answer by highpockets · Apr 28, 2020 at 09:56 PM
Have you taken a look at the documentation for instantiate?? One of the arguments of instantiate is a parent transform.
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
You can also set it afterward:
plate.transform.parent = nasi.transform;
Or vice versa..