Hi Unity-Comunity,
my first Post here, and I am just beginner with Unity, so sorry, if my Questions are banal or simply, but I can’t find a way.
What I try is to generate a sphere (a bigger one) and inside of it, I won’t to generate small spheres.
Something like that, only in 3D:
Practical would it be (as a Bonus) if the Mother sphere would automatically grow up, with more inner spheres (cells).
I want that everything is made by script (C#).
I found a way to set parent, but I can’t position it really inside…
Some hints would be nice.
Here some lines of Code, how far I come…
void generateMother () {
Mother = GameObject.CreatePrimitive(PrimitiveType.Sphere);
Mother.AddComponent <EventListener1>();
Mother.AddComponent <Mothers_Script>();
Mother.name = "Mother";
Mother.GetComponent<MeshRenderer>().material = mother_material;
Rigidbody MotherRigidBody = Mother.AddComponent<Rigidbody>();
MotherRigidBody.mass = 1; // Set the GO's mass to 1 via the Rigidbody.
/*
* generating single inside
* cell of mother Object
*/
Debug.Log(Mother.transform.position);
GameObject myFirstSingleZell = generateSingleZell ();
myFirstSingleZell.transform.parent = Mother.transform;
Debug.Log(Mother.transform.position);
Debug.Log(myFirstSingleZell.transform.position);
//generateStartPopulation();
}
GameObject generateSingleZell () {
GameObject singleCell = GameObject.CreatePrimitive(PrimitiveType.Sphere);
singleCell.name = "Cell";
singleCell.GetComponent<MeshRenderer>().material = mother_cell_material;
Rigidbody CellRigidBody = singleCell.AddComponent<Rigidbody>();
CellRigidBody.mass = 1; // Set the GO's mass to 1 via the Rigidbody.
singleCell.transform.localScale += new Vector3(-0.5F, -0.5F, -0.5F);
return singleCell;
}
Thanks for help