// Use this for external initialization
        void Start()
        {
            cityManager = CityManager.Instance;
            Transform child;

            if (recursionLevel == 0)
            {
                int meshNum = myProfile.groundBlocks.Length;
                int matNum  = myProfile.groundMaterials.Length;
                myMesh     = myProfile.groundBlocks[Random.Range(0, meshNum)];
                myMaterial = myProfile.groundMaterials[Random.Range(0, matNum)];
            }

            myMeshFilter.mesh   = myMesh;
            myRenderer.material = myMaterial;

            if (recursionLevel < maxLevel)
            {
                if (recursionLevel == maxLevel - 1)
                {
                    child = Instantiate(basePrefab, transform.position + Vector3.up, 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)]);
                }
                else
                {
                    child = Instantiate(basePrefab, transform.position + Vector3.up, 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)]);
                }
            }
        }
Exemple #2
0
        // 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);
                    }
                }
            }
        }
Exemple #3
0
        // Use this for external initialization
        void Start()
        {
            cityManager = CityManager.Instance;

            myMeshFilter.mesh   = cityManager.meshArray[(int)myType];
            myRenderer.material = cityManager.materialArray[myMaterial];
            if (recursionLevel < maxLevel)
            {
                Transform child = Instantiate(basePrefab, transform.position + Vector3.up, Quaternion.identity, this.transform);
                child.GetComponent <RecursiveTowerBlock>().Initialize(recursionLevel + 1, (blockType)Random.Range(0, 9), Random.Range(0, 6));
            }
        }
Exemple #4
0
        // Use this for internal initialization
        void Awake()
        {
            if (_instance == null)
            {
                _instance = this;
            }

            else
            {
                Destroy(gameObject);
                Debug.LogError("Multiple CityManager instances in Scene. Destroying clone!");
            };
        }
Exemple #5
0
        // Use this for internal initialization
        void Awake()
        {
            //Checks to see if there's already a CityManager in scene, destroys if there is
            if (_instance == null)
            {
                _instance = this;
            }

            else
            {
                Destroy(gameObject);
                Debug.LogError("Multiple CityManager instances in Scene. Destroying clone!");
            };
        }
        // Start is called before the first frame update
        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;

            if (!cityManager.CheckSlot(x, y, z))
            {
                Destroy(gameObject);
            }
            else
            {
                //Road Tile is Placed
            }
        }
        // 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;
            }
        }