Пример #1
0
// Use this for initialization
    void Start()
    {
        Gold   = 20;
        Wave   = 0;
        Health = 100;
        for (int idx = 0; idx < BaseTowerList.Count; idx += 1)
        {
            BaseTower  tower    = Instantiate(BaseTowerList[idx]);
            GameObject template = Instantiate(Resources.Load("Prefabs/TowerTemplate") as GameObject);
            int        tmp      = idx + 1;
            template.name = "Tower" + tmp.ToString();
            template.transform.SetParent(CanvasTower.transform);
            template.GetComponent <RectTransform>().anchoredPosition = new Vector3(0, 30 + idx * 60, 0);
            GameObject name = template.transform.Find("Name").gameObject;
            name.GetComponent <Text>().text = tower.GetName() + " : " + tmp.ToString();
            GameObject price = template.transform.Find("Price").gameObject;
            price.GetComponent <Text>().text = tower.GetLevelUpPrice() + " Credits";
            GameObject image = template.transform.Find("Image").gameObject;
            Image      i     = image.GetComponent <Image>();
            i.color = tower.GetBaseSprite().color;
            Destroy(tower.gameObject);
        }
    }
Пример #2
0
    void Update()
    {
        int input = 0;

        if (Input.GetButtonDown("Jump"))
        {
            Jump();
            if (CanJump())
            {
                AudioSource audioSource = gameObject.GetComponent <AudioSource>();
                AudioSource.PlayClipAtPoint(audioSource.clip, transform.position);
            }
        }
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            input = 1;
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            input = 2;
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            input = 3;
        }
        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            input = 4;
        }
        if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            input = 5;
        }
        if (input != 0)
        {
            if (gameManager.Gold > gameManager.BaseTowerList[input - 1].GetLevelUpPrice())
            {
                GameObject newTower = Instantiate(gameManager.BaseTowerList[input - 1].gameObject);
                newTower.transform.position = transform.position;
                gameManager.Gold           -= gameManager.BaseTowerList[input - 1].GetLevelUpPrice();
            }
        }

        BaseEntity tower = GetActiveTurret();

        if (_oldTower && tower != _oldTower)
        {
            _oldTower.DeactiveHiglight();
        }
        _oldTower = null;
        if (tower)
        {
            if (tower != _oldTower)
            {
                tower.ActiveHiglight();
            }
            BaseTower lvl = tower.GetComponent <BaseTower>();
            gameManager.Upgrade = lvl.GetLevelUpPrice();
            gameManager.Sell    = lvl.GetSellPrice();

            if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                if (lvl.GetLevelUpPrice() != -1 && gameManager.Gold >= lvl.GetLevelUpPrice())
                {
                    gameManager.Gold -= lvl.GetLevelUpPrice();
                    lvl.LevelUp();
                }
            }
            if (Input.GetKeyDown(KeyCode.Alpha8))
            {
                gameManager.Gold += lvl.GetSellPrice();
                Destroy(lvl.gameObject);
            }
            else
            {
                _oldTower = tower;
            }
        }
        else
        {
            gameManager.Upgrade = 0;
            gameManager.Sell    = 0;
        }
    }