Ejemplo n.º 1
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;
        }
    }