Пример #1
0
    public void Confirm()
    {
        if (GameObject.Find("ConstructSanctum(Clone)") != null)
        {
            ConstructSanctum sanctum = GameObject.Find("ConstructSanctum(Clone)").GetComponent <ConstructSanctum>();

            if (sanctum.IsValid())
            {
                World      world       = GameObject.Find("World").GetComponent <World>();
                GameObject newBuilding = Instantiate(world.getBuildingList()[0].prefab);
                newBuilding.transform.position = sanctum.transform.position;
                Destroy(sanctum.gameObject);
                world.AddGold(-200);
                ControlObjects();
            }
        }
        if (GameObject.Find("ConstructFarm(Clone)") != null)
        {
            ConstructFarm farm = GameObject.Find("ConstructFarm(Clone)").GetComponent <ConstructFarm>();

            if (farm.IsValid())
            {
                World      world       = GameObject.Find("World").GetComponent <World>();
                GameObject newBuilding = Instantiate(world.getBuildingList()[1].prefab);
                newBuilding.transform.position = farm.transform.position;
                if (farm.GetDirection() % 2 == 1)
                {
                    newBuilding.transform.GetChild(0).transform.localScale = new Vector3(newBuilding.transform.GetChild(0).transform.localScale.y, 0.1f * farm.transform.GetChild(0).transform.localScale.x, farm.transform.GetChild(0).transform.localScale.z);
                    newBuilding.transform.GetChild(0).transform.Translate(new Vector3(-0.05f, -0.05f), Space.World);
                    newBuilding.transform.GetChild(1).transform.localScale   = new Vector3(-newBuilding.transform.GetChild(1).transform.localScale.x, farm.transform.GetChild(1).transform.localScale.y, farm.transform.GetChild(1).transform.localScale.z);
                    newBuilding.GetComponent <BuildingObject>().HPBarOffsetX = -0.1f;
                    int size = newBuilding.transform.GetComponentsInChildren <SpriteRenderer>(true).Length;
                    newBuilding.transform.GetComponentsInChildren <SpriteRenderer>(true)[size - 2].gameObject.transform.localPosition = new Vector3(-0.1f, 0, -0.2f);
                }
                Destroy(farm.gameObject);
                world.AddGold(-100);
                world.AddWater(-3);
                ControlObjects();
            }
        }
        if (GameObject.Find("ConstructFence(Clone)") != null)
        {
            ConstructFence fence = GameObject.Find("ConstructFence(Clone)").GetComponent <ConstructFence>();

            if (fence.IsValid())
            {
                World      world       = GameObject.Find("World").GetComponent <World>();
                GameObject newBuilding = Instantiate(world.getBuildingList()[2].prefab);
                newBuilding.transform.position = fence.transform.position;
                newBuilding.transform.GetChild(0).transform.rotation = fence.transform.GetChild(0).transform.rotation;
                newBuilding.transform.GetChild(1).transform.rotation = fence.transform.GetChild(1).transform.rotation;
                Destroy(fence.gameObject);
                world.AddGold(-50);
                world.AddGarlic(-1);
                ControlObjects();
            }
        }
    }