Hi,
I’m trying to instantiate a number X of gameObjects as children of a gameObject A (on which the script is attached).
when i’m instantiating them not as children, everythings goes as planned.
But when i SetParent them, another gameObject gets instantiated as the child of the child of my gameObject A.
Here’s the code where the magic happens. The fact that i use a coroutine change nothing the situation.
IEnumerator CreateSpineDeformation(float halfSizeY, float scaleCoefficient, int iterations)
{
GameObject deformation = Instantiate(gameObject) as GameObject;
deformation.transform.position = transform.position + Vector3.up * halfSizeY;
deformation.transform.localScale = transform.localScale / scaleCoefficient;
deformation.transform.RotateAround(transform.position, transform.up, UnityEngine.Random.Range(rotateUpCoef * -1, rotateUpCoef));
deformation.transform.RotateAround(transform.position, transform.right, UnityEngine.Random.Range(rotateRightCoef * -1, rotateRightCoef));
deformation.transform.RotateAround(transform.position, transform.forward, UnityEngine.Random.Range(rotateForwardCoef * -1, rotateForwardCoef));
deformation.transform.SetParent(transform); //HERE
DeformationManager deformationManager = deformation.GetComponent<DeformationManager>();
deformationManager.iterations = iterations;
deformationManager.scaleCoefficient = scaleCoefficient;
deformationManager.sources = 1;
yield return null;
}
Here is where i call it
void StartDeformation() {
for (int i = 0; i < sources && iterations > 0; i++) {
StartCoroutine(CreateSpineDeformation(source.GetComponent<Renderer>().bounds.size.y / spawnPositionRatio, scaleCoefficient, iterations - 1));
}
}
It’s my first time uploading to this forum. Hopes i’m posting right.
Thank you !