Esempio n. 1
0
    public void SelectTower(int index)
    {
        UIManager.instance.RegisterUIClick();

        TowerData.Level selectedTower = GameData.instance.GetCurrentLevel().towers[index];
        // Calculate cost for new tower
        int towerCost = (int)selectedTower.GetProperty(GameData.GameProperies.COST);

        if (towerCost == 0)
        {
            towerCost = 100;
        }

        // If there are enough money to build the tower, deduct them
        if (Currency.instance.UseCoins(towerCost))
        {
            // Build the tower
            GameObject towerObject = Instantiate(selectedTower.tower.GetPrefab(), selectedPlane.transform.position, Quaternion.identity) as GameObject;
            Tower      tower       = towerObject.GetComponent <Tower>();
            tower.transform.parent = towersRoot;
            selectedPlane.tag      = Grid.PLANE_NO_HOVER;

            // Place the tower on the grid
            GamePlay.instance.activeTowers.Add(tower);
        }

        HideBuildTowerUI();
    }
Esempio n. 2
0
        public Boolean BuildTower(int index, double[] pos)
        {
            /**
             * index    - tower type eg: 0 means gun tower
             * position - where to build tower
             */

            UIManager.instance.RegisterUIClick();

            // set screen Position
            Vector3 Position = Vector3.zero;

            Position.x = (float)pos [0];
            Position.y = 0.0f;
            Position.z = (float)pos [1];

            TowerData.Level selectedTower = GameData.instance.GetCurrentLevel().towers [index];
            // Calculate cost for new tower
            int towerCost = (int)selectedTower.GetProperty(GameData.GameProperies.COST);

            if (towerCost == 0)
            {
                towerCost = 100;
            }



            // If there are enough money to build the tower, deduct them
            if (Currency.instance.UseCoins(towerCost))
            {
                // Build the tower
                GameObject towerObject = Instantiate(selectedTower.tower.GetPrefab(), Position, Quaternion.identity) as GameObject;
                String     posStr      = "";
                posStr += (int)pos [0];
                posStr += ",";
                posStr += (int)pos [1];
                gameObjMap [posStr] = towerObject;


                Tower tower = towerObject.GetComponent <Tower> ();
                tower.transform.parent = towersRoot;
                tower.level            = 1;
//				selectedPlane.tag = Grid.PLANE_NO_HOVER;

                // Place the tower on the grid
                GamePlay.instance.activeTowers.Add(tower);

                int neg_value = -towerCost;
                Debug.Log("{\t\"Type\": \"Tower\",\t\"TowerName\": \"" + selectedTower.name + "\",\t\"TowerIndex\": " + selectedTower.index + ",\t\"Level\": \"1,1\",\t\"Position\": \"" + posStr + "\",\t\"Event\": \"Built\",\t\"Money\": " + neg_value + ",\t\"Time\": " + (int)Time.time + "}, ");
                Collector.Instance.spendMoney += neg_value;
                return(true);
            }
            return(false);
        }