// 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 = HostileCityManager.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 <HostileTowerBlock>().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 <HostileTowerBlock>().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 internal initialization void Awake() { if (_instance == null) { _instance = this; } else { Destroy(gameObject); Debug.LogError("Multiple HostileCityManager instances in Scene. Destroying clone!"); }; }