private int AddPlane(GameObject lifeForm, int i, ref List <byte> geneticCode, List <byte> buildingInstructions) { if (debbuging) { Debug.Log($"The difference between i{i} + 6 = {i + 6} and geneticCode.Count ({geneticCode.Count}) is {i + 6 - geneticCode.Count}"); } if (i + 6 > geneticCode.Count) { if (debbuging) { Debug.Log($"L3+ (Size Before) = {geneticCode.Count}"); } for (int j = 0; j < i + 6 - geneticCode.Count + 3; j++) { geneticCode.Add((byte)Random.Range(0, 255)); } if (debbuging) { Debug.Log($"L3+ (Size After) = {geneticCode.Count}"); } } if (debbuging) { Debug.Log($"L3: (Size = {geneticCode.Count}"); } GameObject plane = new GameObject("Plane"); Vector3 dimensions = new Vector3(0.5f, 0.01f, 1f); meshGenerator.AddTwoDimMesh(plane, Vector3.zero, dimensions); //Debug.Log($"{i} = {geneticCode[i]} - Scale"); float scale = (float)geneticCode[i]; if (scale > 1) { scale = 1; } if (debbuging) { Debug.Log("L3...1"); } //plane.transform.localScale = new Vector3(1, 1, scale); //Debug.Log("Added Scale"); i++; float xRot = geneticCode[i++] * 1.41f; if (debbuging) { Debug.Log("L3...2"); } float yRot = geneticCode[i++] * 1.41f; if (debbuging) { Debug.Log("L3...3"); } float zRot = geneticCode[i++] * 1.41f; if (debbuging) { Debug.Log("L3...4"); } //Debug.Log("Added Rotations"); List <GameObject> parts = lifeForm.GetComponent <LifeFormExec>().GetParts(); //SphereCollider sc = sphere.AddComponent(typeof(SphereCollider)) as SphereCollider; //Debug.Log($"{i} = {geneticCode[i]}"); if (debbuging) { Debug.Log($"L3... (Size = {geneticCode.Count} and i = {i}"); } bool processed = false; do { switch (geneticCode[i]) { case (byte)AttachClass.ToCenter: if (debbuging) { Debug.Log("L3-" + AttachClass.ToCenter); } if (parts.Count == 0) { GameObject.Destroy(plane); GameObject.Destroy(lifeForm); } Debug.Log("should be here"); i++; processed = true; break; case (byte)AttachClass.ToLast: if (debbuging) { Debug.Log("L3-" + AttachClass.ToLast); } if (parts.Count == 0) { geneticCode[i] = (byte)GeneticCodes.AttachClass.ToCenter; break; } i++; plane.transform.parent = parts[parts.Count - 1].transform; plane.transform.rotation = parts[parts.Count - 1].transform.rotation; //plane.transform.rotation = Quaternion.Euler(xRot, yRot, 0); plane.name = $"PlaneCell{lifeForm.GetComponent<LifeFormExec>().GetParts().Count}"; plane.GetComponent <Renderer>().enabled = false; plane.tag = "2DStruct"; PartExec partExec = plane.AddComponent <PartExec>(); GameObject.Destroy(plane.GetComponent <SphereCollider>()); partExec.SetPartArea(dimensions.x * dimensions.z / 2); plane.transform.localPosition = new Vector3(0, 0, 0); plane.transform.rotation = Quaternion.Euler(xRot, yRot, 0); partExec.SetIsLocatedAtOrigin(true); //partExec.SetLocalPositionStored(plane.transform.localPosition); lifeForm.GetComponent <LifeFormExec>().GetParts().Add(plane); //attach to last branch processed = true; Debug.Log("Exited"); break; default: System.Array values = GeneticCodes.AttachClass.GetValues(typeof(GeneticCodes.AttachClass)); System.Random random = new System.Random(); byte randomByte = (byte)values.GetValue(random.Next(values.Length)); geneticCode[i] = randomByte; geneticCode[i] = (byte)GeneticCodes.AttachClass.ToLast; //attach to random branch and epigenetics break; } } while (processed == false); //i++; return(i); }