// Use this for external initialization void Start() { int x = Mathf.RoundToInt(transform.position.x + 7.0f); int y = Mathf.RoundToInt(transform.position.y); int z = Mathf.RoundToInt(transform.position.z + 7.0f); cityManager = CityManager.Instance; Transform child; if (recursionLevel == 0) { if (!cityManager.CheckSlot(x, y, z)) { int meshNum = myProfile.groundBlocks.Length; int matNum = myProfile.groundMaterials.Length; myMesh = myProfile.groundBlocks[Random.Range(0, meshNum)]; myMaterial = myProfile.groundMaterials[Random.Range(0, matNum)]; cityManager.SetSlot(x, y, z, true); } else { Destroy(gameObject); } } myMeshFilter.mesh = myMesh; myRenderer.material = myMaterial; if (recursionLevel < maxLevel) { if (recursionLevel == maxLevel - 1) { if (!cityManager.CheckSlot(x, y + 1, z)) { child = Instantiate(basePrefab, transform.position + Vector3.up * 1.05f, Quaternion.identity, this.transform); int meshNum = myProfile.roofBlocks.Length; int matNum = myProfile.roofMaterials.Length; child.GetComponent <DeluxeTowerBlock>().Initialize(recursionLevel + 1, myProfile.roofMaterials[Random.Range(0, matNum)], myProfile.roofBlocks[Random.Range(0, meshNum)]); cityManager.SetSlot(x, y + 1, z, true); } } else { if (!cityManager.CheckSlot(x, y + 1, z)) { child = Instantiate(basePrefab, transform.position + Vector3.up * 1.05f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; child.GetComponent <DeluxeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum)]); cityManager.SetSlot(x, y + 1, z, true); } } } }
// Use this for external initialization void Start() { int x = Mathf.RoundToInt(transform.position.x + 7.0f); int y = Mathf.RoundToInt(transform.position.y); int z = Mathf.RoundToInt(transform.position.z + 7.0f); cityManager = CityManager.Instance; treePrefab = cityManager.treePrefab; GameObject child; if (recursionLevel == 0) //initial foundation block { if (!cityManager.CheckSlot(x, y, z)) { cityManager.SetSlot(x, y, z, true); int meshNum = myProfile.groundBlocks.Length; int matNum = myProfile.groundMaterials.Length; myMesh = myProfile.groundBlocks[Random.Range(0, meshNum)]; myMaterial = myProfile.groundMaterials[Random.Range(0, matNum)]; } else { GameObject.Destroy(gameObject); } } myMeshFilter.mesh = myMesh; myRenderer.material = myMaterial; if (recursionLevel < maxLevel) { if (recursionLevel == maxLevel - 1) //the next segment placed will be a roof { if (!cityManager.CheckSlot(x, y + 1, z)) { cityManager.SetSlot(x, y + 1, z, true); child = Instantiate(treePrefab, transform.position + Vector3.up * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.roofBlocks.Length; int matNum = myProfile.roofMaterials.Length; Debug.Log(child.GetComponents <TreeTowerBlock>().Length); child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.roofMaterials[Random.Range(0, matNum)], myProfile.roofBlocks[Random.Range(0, meshNum)]); } } else //the next segment placed will be a main body segment { int random = Random.Range(0, 10); if ((y < 5) || (random < 6)) //the low altitude vertical tower section { if (!cityManager.CheckSlot(x, y + 1, z)) { cityManager.SetSlot(x, y + 1, z, true); child = Instantiate(treePrefab, transform.position + Vector3.up * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum)]); } } else //here we start branching off our tree tower { //MODIFY THE CODE BELOW random = Random.Range(0, 10); if ((random < 5) && (!cityManager.CheckSlot(x, y + 1, z))) { cityManager.SetSlot(x, y + 1, z, true); child = Instantiate(treePrefab, transform.position + Vector3.up * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; Debug.Log(child.GetComponents <TreeTowerBlock>().Length); child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum)]); } ; random = Random.Range(0, 10); if ((random < 5) && (!cityManager.CheckSlot(x, y + 1, z))) { cityManager.SetSlot(x, y + 1, z, true); child = Instantiate(treePrefab, transform.position + Vector3.up * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; Debug.Log(child.GetComponents <TreeTowerBlock>().Length); child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum)]); } ; random = Random.Range(0, 10); if ((random < 5) && (!cityManager.CheckSlot(x, y + 1, z))) { cityManager.SetSlot(x, y + 1, z, true); child = Instantiate(treePrefab, transform.position + Vector3.up * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; Debug.Log(child.GetComponents <TreeTowerBlock>().Length); child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum)]); } ; random = Random.Range(0, 10); if ((random < 5) && (!cityManager.CheckSlot(x, y + 1, z))) { cityManager.SetSlot(x, y + 1, z, true); child = Instantiate(treePrefab, transform.position + Vector3.up * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; Debug.Log(child.GetComponents <TreeTowerBlock>().Length); child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum)]); } ; //END MODIFY CODE random = Random.Range(0, 10); if ((random < 5) && (!cityManager.CheckSlot(x, y + 1, z))) { cityManager.SetSlot(x, y + 1, z, true); child = Instantiate(treePrefab, transform.position + Vector3.up * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; Debug.Log(child.GetComponents <TreeTowerBlock>().Length); child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum)]); } ; } } } }
// Use this for external initialization void Start() { int x = Mathf.RoundToInt(transform.position.x + 7.0f); int y = Mathf.RoundToInt(transform.position.y); int z = Mathf.RoundToInt(transform.position.z + 7.0f); cityManager = CityManager.Instance; Transform child; if (recursionLevel == 0) { if (!cityManager.CheckSlot(x, y, z) && !cityManager.CheckRoadSlot(x, y, z)) { int meshNum = myProfile.groundBlocks.Length; int matNum = myProfile.groundMaterials.Length; myMesh = myProfile.groundBlocks[Random.Range(0, meshNum)]; myMaterial = myProfile.groundMaterials[Random.Range(0, matNum)]; cityManager.SetSlot(x, y, z, true); cityManager.SetBuildingSlot(x, y, z, true); } else { Destroy(gameObject); } } myMeshFilter.mesh = myMesh; myRenderer.material = myMaterial; if (recursionLevel < maxLevel) { if (recursionLevel == maxLevel - 1) { if (!cityManager.CheckSlot(x, y + 1, z)) { //Randomise roof rotation int random = Random.Range(0, 3); switch (random) { case 0: roofRotation = Quaternion.Euler(0, 0, 0); break; case 1: roofRotation = Quaternion.Euler(0, 90, 0); break; case 2: roofRotation = Quaternion.Euler(0, 180, 0); break; case 3: roofRotation = Quaternion.Euler(0, 270, 0); break; } child = Instantiate(basePrefab, transform.position + Vector3.up * 1f, roofRotation, this.transform); int meshNum = myProfile.roofBlocks.Length; int matNum = myProfile.roofMaterials.Length; child.GetComponent <DeluxeTowerBlock>().Initialize(recursionLevel + 1, myProfile.roofMaterials[Random.Range(0, matNum)], myProfile.roofBlocks[Random.Range(0, meshNum)]); cityManager.SetSlot(x, y + 1, z, true); cityManager.SetBuildingSlot(x, y + 1, z, true); } } else { if (!cityManager.CheckSlot(x, y + 1, z)) { child = Instantiate(basePrefab, transform.position + Vector3.up * 1f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; child.GetComponent <DeluxeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum)]); cityManager.SetSlot(x, y + 1, z, true); cityManager.SetBuildingSlot(x, y + 1, z, true); } } } //If the block is surrounded on all sides, turn off the Renderer if ((cityManager.CheckBuildingSlot(x, y + 1, z) && cityManager.CheckBuildingSlot(x, y - 1, z) && cityManager.CheckBuildingSlot(x + 1, y, z) && cityManager.CheckBuildingSlot(x + 1, y, z) && cityManager.CheckBuildingSlot(x, y, z + 1) && cityManager.CheckBuildingSlot(x, y, z - 1))) { //if the building is beside the road, don't turn off Renderer if (!(cityManager.CheckRoadSlot(x + 1, 1, z) || cityManager.CheckRoadSlot(x + 1, 1, z) || cityManager.CheckRoadSlot(x, 1, z + 1) || cityManager.CheckRoadSlot(x, 1, z - 1))) { if (x != 0 && y != 1 && z != 0) { myRenderer.enabled = false; } } } //Fix random invisble walls if (x == 17 || x == 22 || x == 23) { myRenderer.enabled = true; } }