- Home /
Changing Prefab's child position after Instantiate
Hello Guys, I am making Spinning Endless Runner game. I have watermelons to slice. Here is a video: https://streamable.com/jwfrmw
I can slice watermelons until 8th second. my second instantiated prefab is coming after that. My first and second prefab's children have exact same position. I need watermelon's position to slice. However, my slicing always happening at 1st prefab's position.
here is my prefab.
private void spawnTile(int prefabIndex = -1)
{
GameObject go;
go = Instantiate(tilePrefabs[0]) as GameObject;
go.transform.SetParent(transform);
go.transform.position = Vector3.forward * spawnZ;
spawnZ += tileLength;
}
I tried localPosition instead of go.transform.position it didnt work.
Answer by CenkTuna · Sep 02, 2020 at 12:43 AM
Hi guys.
localPosition is a common answer but it isn't for me. make sure that your gameobject's transform.position right. I used Debug.Log and i understand that my transform.position is not right. https://prnt.sc/u9y24z That update fixed my problem.
SlicedHull kesilenNesne = Kes(nesne.GetComponent<Collider>().gameObject, mat);
GameObject kesilmisUst = kesilenNesne.CreateUpperHull(nesne.gameObject, mat);
kesilmisUst.transform.position = nesne.gameObject.transform.position;
GameObject kesilmisAlt = kesilenNesne.CreateLowerHull(nesne.gameObject, mat);
kesilmisAlt.transform.position = nesne.gameObject.transform.position;