Beispiel #1
0
    public void BuySelected()
    {
        //Called from button, so need to get variables from main gameManager ↓
        if (GetGameManager().selectedTile != null && UIManager.GetUIManager().currentSelection != -1)
        {
            float buildingCost = UIManager.GetUIManager().lastBuilding.GetComponent <BuildingCost>().cost;

            if (!MoneyTracker.GetMoneyTracker().CanAfford(buildingCost))
            {
                AudioManager.GetAudioManager().PlayDenied();
                return;
            }

            MoneyTracker.GetMoneyTracker().BuyFor(buildingCost);

            GameObject gameObject = UIManager.GetUIManager().lastBuilding;

            if (gameObject.name == "Nuclear Plant" && !GetGameManager().nuclearAlready)
            {
                SnapshotManager.GetSnapshotManager().FirstNuclear();
            }
            else
            {
                GetGameManager().nuclearAlready = true;
            }

            if (GetGameManager().selectedTile.CreateBuilding(UIManager.GetUIManager().lastBuilding))
            {
                UIManager.GetUIManager().lastBuilding.GetComponent <BuildSound>().Play();
            }
            UIManager.GetUIManager().ShowMenu(true, GetGameManager().selectedTile);
        }
    }
Beispiel #2
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (!EventSystem.current.IsPointerOverGameObject())
            {
                if (Physics.Raycast(ray, out hit, 100, LayerMask.GetMask("Tile", "UI")))
                {
                    if (selectedTile != null)
                    {
                        selectedTile.Select(false);
                    }

                    selectedTile = hit.transform.gameObject.GetComponent <Tile>();
                    selectedTile.Select(true);

                    UIManager.GetUIManager().ShowMenu(true, selectedTile);
                    AudioManager.GetAudioManager().PlaySelect();
                }
                else
                {
                    if (selectedTile != null)
                    {
                        selectedTile.Select(false);
                        selectedTile = null;
                        UIManager.GetUIManager().ShowMenu(false, null);
                    }
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            if (selectedTile != null)
            {
                if (!MoneyTracker.GetMoneyTracker().CanAfford(poleCost))
                {
                    AudioManager.GetAudioManager().PlayDenied();
                    return;
                }
                else
                {
                    if (selectedTile.CreateBuilding(pole))
                    {
                        MoneyTracker.GetMoneyTracker().BuyFor(poleCost);
                        pole.GetComponent <BuildSound>().Play();
                        UIManager.GetUIManager().ShowMenu(true, selectedTile);
                    }
                }
            }
        }

        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }
    }
Beispiel #3
0
    public bool CreateBuilding(GameObject buildingPrefab)
    {
        if (building == null && type == Type.Grass)
        {
            building      = Instantiate(buildingPrefab, transform.position, buildingPrefab.transform.rotation);
            building.name = buildingPrefab.name;
            building.GetComponent <CableManager>().CheckBordering(gridPosition, true);

            EnergyConsumer ec = building.GetComponent <EnergyConsumer>();
            EnergyProducer ep = building.GetComponent <EnergyProducer>();

            if (ec != null)
            {
                PowerTracker.GetPowerTracker().totalConsumption += ec.energyConsumption;
                MoneyTracker.GetMoneyTracker().totalIncome      += ec.moneyPerSecond;
            }

            if (ep != null)
            {
                PowerTracker.GetPowerTracker().totalProduction += ep.energyProduction;
                MoneyTracker.GetMoneyTracker().totalUpkeep     += ep.moneyPerSecond;
            }
            return(true);
        }
        return(false);
    }
Beispiel #4
0
 // Update is called once per frame
 void Update()
 {
     moneyText.text       = "Money: " + Mathf.RoundToInt(MoneyTracker.GetMoneyTracker().money) + "₡";
     incomeText.text      = "Global Income: " + Mathf.RoundToInt(MoneyTracker.GetMoneyTracker().totalIncome) + "₡/s";
     upkeepText.text      = "Global Upkeep: " + Mathf.RoundToInt(MoneyTracker.GetMoneyTracker().totalUpkeep) + "₡/s";
     productioText.text   = "Global Production: " + Mathf.RoundToInt(PowerTracker.GetPowerTracker().totalProduction) + "PU/s";
     consumptionText.text = "Global Consumption: " + Mathf.RoundToInt(PowerTracker.GetPowerTracker().totalConsumption) + "PU/s";
 }
Beispiel #5
0
    public void SellSelected()
    {
        float buildingCost = GetGameManager().selectedTile.building.GetComponent <BuildingCost>().cost;

        MoneyTracker.GetMoneyTracker().SellFor(buildingCost);

        GetGameManager().selectedTile.DestoryBuilding();
        AudioManager.GetAudioManager().PlaySell();
        UIManager.GetUIManager().ShowMenu(true, GetGameManager().selectedTile);
    }
Beispiel #6
0
    public void DestoryBuilding()
    {
        EnergyConsumer ec = building.GetComponent <EnergyConsumer>();
        EnergyProducer ep = building.GetComponent <EnergyProducer>();

        if (ec != null)
        {
            PowerTracker.GetPowerTracker().totalConsumption -= ec.energyConsumption;
            MoneyTracker.GetMoneyTracker().totalIncome      -= ec.moneyPerSecond;
        }

        if (ep != null)
        {
            PowerTracker.GetPowerTracker().totalProduction -= ep.energyProduction;
            MoneyTracker.GetMoneyTracker().totalUpkeep     -= ep.moneyPerSecond;
        }

        building.GetComponent <CableManager>().Remove(gridPosition, -1);
        Destroy(building);
        building = null;
    }