示例#1
0
    //Gets tower id when a player clicks the tower ui,creates the object,and starts hovering it
    public void TowerHover(int i)
    {
        GameObject tower1, tower2, tower3, tower4, tower5, tower6;
        GameObject new_tower = null;

        tower1 = (GameObject)Resources.Load("Prefabs/Towers/Tower", typeof(GameObject));
        tower2 = (GameObject)Resources.Load("Prefabs/Towers/Slow Tower", typeof(GameObject));
        tower3 = (GameObject)Resources.Load("Prefabs/Towers/Buff Tower", typeof(GameObject));
        tower4 = (GameObject)Resources.Load("Prefabs/Towers/RoundHouse Tower", typeof(GameObject));
        tower5 = (GameObject)Resources.Load("Prefabs/Towers/Global Tower", typeof(GameObject));
        tower6 = (GameObject)Resources.Load("Prefabs/Towers/Canon Tower", typeof(GameObject));;

        Vector2 coords = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        coords = new Vector2(Mathf.Round(coords.x), Mathf.Round(coords.y));

        switch (i)
        {
        case 1:
            new_tower      = Instantiate(tower1, coords, Quaternion.identity);
            new_tower.name = "Tower";
            break;

        case 2:
            new_tower      = Instantiate(tower2, coords, Quaternion.identity);
            new_tower.name = "Slow Tower";
            break;

        case 3:
            new_tower      = Instantiate(tower3, coords, Quaternion.identity);
            new_tower.name = "Buff Tower";
            break;

        case 4:
            new_tower      = Instantiate(tower4, coords, Quaternion.identity);
            new_tower.name = "RoundHouse Tower";
            break;

        case 5:
            new_tower      = Instantiate(tower5, coords, Quaternion.identity);
            new_tower.name = "Global Tower";
            break;

        case 6:
            new_tower      = Instantiate(tower6, coords, Quaternion.identity);
            new_tower.name = "Canon Tower";
            break;
        }
        new_tower.GetComponent <Hover>().enabled = true;
        new_tower.GetComponent <Hover>().setTowerCost(TowerCost.getCost(i));
    }
    //Γίνεται η πώληση του πύργου
    public void SellTower()
    {
        int value = TowerCost.getTowerSellValue(ttype, tlevel);

        this.GetComponent <Player>().UpdateGold(value);

        //Απελευθερώνει το tile που ήταν ο πύργος
        int    x        = (int)SelectedTower.transform.position.x;
        int    y        = (int)SelectedTower.transform.position.y;
        string tilename = "G " + x + "," + y;

        GameObject.Find(tilename).GetComponent <GrassTile>().setCanPlaceBuilding(true);

        //Αφαιρείται ο πύργος από το παιχνίδι
        GetComponent <Player>().AddInTowerList(SelectedTower.GetComponentInChildren <Tower>().Id, false);
        Destroy(SelectedTower);
        CancelTowerMenu();
    }
示例#3
0
 void Start()
 {
     //Μετατρέπει τα κόστη των πύργων σε κείμενο για το χρήστη
     for (int i = 1; i < 7; i++)
     {
         string towername = "Tower " + i;
         GameObject.Find(towername).transform.Find("Cost").GetComponent <Text>().text = TowerCost.getCost(i).ToString();
     }
 }
    //Αναβάθμιση πύργου
    public void UpgradeTower()
    {
        int cost = TowerCost.getUpgradeCost(ttype, tlevel);

        if (this.GetComponent <Player>().Money >= cost)
        {
            if (tlevel < 3)
            {
                SelectedTower.GetComponentInChildren <Tower>().Towerlevel = tlevel + 1;

                //Γίνεται η αφαίρεση των χρημάτων για την αναβάθμιση και
                this.GetComponent <Player>().UpdateGold(-cost);

                //Eνημερώνονται οι μεταβλητές για τις ιδιότητες του πύργου
                int   damage;
                float atk_cool;
                float proj_sp;
                int   eff_val;
                float range;

                damage   = TowerUpgrades.Damage;
                atk_cool = TowerUpgrades.Atk_cool;
                proj_sp  = TowerUpgrades.Proj_sp;
                eff_val  = TowerUpgrades.Eff_val;
                range    = TowerUpgrades.Range;

                if (damage != 0)
                {
                    SelectedTower.GetComponentInChildren <Tower>().Damage = damage;
                }

                if (atk_cool != 0)
                {
                    SelectedTower.GetComponentInChildren <Tower>().AttackCooldown = atk_cool;
                }

                if (proj_sp != 0)
                {
                    SelectedTower.GetComponentInChildren <Tower>().ProjectileSpeed = proj_sp;
                }

                if (eff_val != 0)
                {
                    SelectedTower.GetComponentInChildren <Tower>().EffectValue = eff_val;
                }


                if (range != 0)
                {
                    SelectedTower.transform.Find("Range").transform.localScale = new Vector3(range, range, 1);
                    SelectedTower.GetComponentInChildren <Tower>().UpdateRange();
                }

                CancelTowerMenu();
            }

            else
            {
                InfoMessage.GetComponent <ShowInfoText>().displayMessage(4);
            }
        }
    }
 //Οριίζει το κείμενο στα κουμπια του μένού των πύργων
 public void UpdateMenu()
 {
     TowerMenu.transform.Find("UpgradeButton").GetComponentInChildren <Text>().text = "UPGRADE(" + TowerCost.getUpgradeCost(ttype, tlevel) + ")";
     TowerMenu.transform.Find("SellButton").GetComponentInChildren <Text>().text    = "SELL(" + TowerCost.getTowerSellValue(ttype, tlevel) + ")";
 }