Пример #1
0
    protected void addBuildingToScene(Vector3 position)
    {
        //GameObject currentObject = FindObjectOfType<All3DObjects>().getCurrentObject();

        // Ici ajouter currentObject = batiment selectionné

        if (currentObject != null)
        {
            Debug.Log("OK");
            //Instantiate

            _myVillage = FindObjectOfType <VillageManager>();
            Debug.Log(currentObject.name);
            switch (currentObject.name)
            {
            case "BasicHousePrefab":
                if (player.getGold() >= 100 && _myVillage.getWood() >= 60 && _myVillage.getStone() >= 30)
                {
                    _myVillage.setStone(_myVillage.getStone() - 30);
                    _myVillage.setWood(_myVillage.getWood() - 60);
                    player.setGold(player.getGold() - 100);
                    _myVillage.setPeople(_myVillage.getPeople() + 5);
                    Instantiate(currentObject, position, Quaternion.identity);
                    CloseMessagePanel();
                    CloseMessageDetailedPanel();
                }
                else
                {
                    OpenMessagePanel("Not enough ressources");
                }

                break;

            case "MediumHousePrefab":
                if (player.getGold() >= 180 && _myVillage.getWood() >= 150 && _myVillage.getStone() >= 100)
                {
                    _myVillage.setStone(_myVillage.getStone() - 100);
                    _myVillage.setWood(_myVillage.getWood() - 150);
                    player.setGold(player.getGold() - 180);
                    _myVillage.setPeople(_myVillage.getPeople() + 10);
                    Instantiate(currentObject, position, Quaternion.identity);
                    CloseMessagePanel();
                    CloseMessageDetailedPanel();
                }
                else
                {
                    OpenMessagePanel("Not enough ressources");
                }
                break;

            case "BigHousePrefab":
                if (player.getGold() >= 300 && _myVillage.getWood() >= 350 && _myVillage.getStone() >= 220)
                {
                    _myVillage.setStone(_myVillage.getStone() - 220);
                    _myVillage.setWood(_myVillage.getWood() - 350);
                    _myVillage.setPeople(_myVillage.getPeople() + 25);
                    player.setGold(player.getGold() - 300);
                    Instantiate(currentObject, position, Quaternion.identity);
                    CloseMessagePanel();
                    CloseMessageDetailedPanel();
                }
                else
                {
                    OpenMessagePanel("Not enough ressources");
                }
                break;

            case "LumberPrefab":
                if (player.getGold() >= 220 && _myVillage.getWood() >= 250)
                {
                    _myVillage.setWood(_myVillage.getWood() - 250);
                    _myVillage.setLumber(_myVillage.getLumber() + 1);
                    player.setGold(player.getGold() - 220);
                    Instantiate(currentObject, position, Quaternion.identity);
                    CloseMessagePanel();
                    CloseMessageDetailedPanel();
                }
                else
                {
                    OpenMessagePanel("Not enough ressources");
                }
                break;

            case "MinerPrefab":
                if (player.getGold() >= 220 && _myVillage.getStone() >= 180)
                {
                    _myVillage.setStone(_myVillage.getStone() - 180);
                    _myVillage.setMiner(_myVillage.getMiner() + 1);
                    player.setGold(player.getGold() - 220);
                    Instantiate(currentObject, position, Quaternion.identity);
                    CloseMessagePanel();
                    CloseMessageDetailedPanel();
                }
                else
                {
                    OpenMessagePanel("Not enough ressources");
                }
                break;

            case "WareHousePrefab":
                if (player.getGold() >= 350 && _myVillage.getStone() >= 350 && _myVillage.getWood() >= 400 && _myVillage.getPeople() >= 30)
                {
                    _myVillage.setWood(_myVillage.getWood() - 400);
                    _myVillage.setStone(_myVillage.getStone() - 350);
                    player.setGold(player.getGold() - 350);
                    player.setMaxWood(player.getMaxWood() + 800);
                    player.setMaxStone(player.getMaxStone() + 600);
                    Instantiate(currentObject, position, Quaternion.identity);
                    CloseMessagePanel();
                    CloseMessageDetailedPanel();
                }
                else if (_myVillage.getPeople() < 30)
                {
                    OpenMessagePanel("Not enough inhabitants");
                }
                else
                {
                    OpenMessagePanel("Not enough ressources");
                }
                break;

            case "GoldWareHousePrefab":
                if (player.getGold() >= 400 && _myVillage.getStone() >= 450 && _myVillage.getWood() >= 500 && _myVillage.getPeople() >= 50)
                {
                    _myVillage.setWood(_myVillage.getWood() - 500);
                    _myVillage.setStone(_myVillage.getStone() - 450);
                    player.setGold(player.getGold() - 400);
                    player.setMaxGold(player.getMaxGold() + 700);
                    Instantiate(currentObject, position, Quaternion.identity);
                    CloseMessagePanel();
                    CloseMessageDetailedPanel();
                }
                else if (_myVillage.getPeople() < 50)
                {
                    OpenMessagePanel("Not enough inhabitants");
                }
                else
                {
                    OpenMessagePanel("Not enough ressources");
                }
                break;

            case "ForgePrefab":
                if (player.getGold() >= 320 && _myVillage.getStone() >= 250 && _myVillage.getWood() >= 300 && _myVillage.getPeople() >= 40)
                {
                    _myVillage.setWood(_myVillage.getWood() - 300);
                    _myVillage.setStone(_myVillage.getStone() - 250);
                    player.setGold(player.getGold() - 320);
                    Instantiate(currentObject, position, Quaternion.identity);
                    player.setDEF(player.getDEF() + 10);
                    CloseMessagePanel();
                    CloseMessageDetailedPanel();
                }
                else if (_myVillage.getPeople() < 40)
                {
                    OpenMessagePanel("Not enough inhabitants");
                }
                else
                {
                    OpenMessagePanel("Not enough ressources");
                }
                break;

            case "ArmureriePrefab":
                if (player.getGold() >= 320 && _myVillage.getStone() >= 240 && _myVillage.getWood() >= 320 && _myVillage.getPeople() >= 40)
                {
                    _myVillage.setWood(_myVillage.getWood() - 320);
                    _myVillage.setStone(_myVillage.getStone() - 240);
                    player.setGold(player.getGold() - 320);
                    player.setATK(player.getATK() + 10);
                    Instantiate(currentObject, position, Quaternion.identity);
                    CloseMessagePanel();
                    CloseMessageDetailedPanel();
                }
                else if (_myVillage.getPeople() < 40)
                {
                    OpenMessagePanel("Not enough inhabitants");
                }
                else
                {
                    OpenMessagePanel("Not enough ressources");
                }
                break;
            }
        }
    }
Пример #2
0
    void Update()
    {
        spdCount += 1;

        if (spdCount >= spdTimer && !freeze)
        {
            playerScript.setGold(playerScript.getGold() - 1);
            spdCount = 0;
        }
        else if (freeze)
        {
            spdCount = 0;
        }


        currentGold = playerScript.getGold() * 100;
        maxGold     = playerScript.getMaxGold() * 100;
        UpdateHealthBar();

        manageMode = playerScript.getManageMode();

        if (!manageMode)
        {
            transform.GetChild(2).GetChild(0).GetChild(1).GetComponent <Text>().text = (currentGold / 100).ToString();
            transform.GetChild(2).GetChild(1).GetChild(1).GetComponent <Text>().text = (playerScript.getWood()).ToString();
            transform.GetChild(2).GetChild(2).GetChild(1).GetComponent <Text>().text = (playerScript.getStone()).ToString();
            transform.GetChild(2).GetChild(3).GetChild(1).GetComponent <Text>().text = (villageScript.getPeople()).ToString();
        }
        else
        {
            transform.GetChild(2).GetChild(0).GetChild(1).GetComponent <Text>().text = (currentGold / 100).ToString();
            transform.GetChild(2).GetChild(1).GetChild(1).GetComponent <Text>().text = (villageScript.getWood()).ToString();
            transform.GetChild(2).GetChild(2).GetChild(1).GetComponent <Text>().text = (villageScript.getStone()).ToString();
            transform.GetChild(2).GetChild(3).GetChild(1).GetComponent <Text>().text = (villageScript.getPeople()).ToString();
        }
    }