Exemple #1
0
    public void ChangeClickState(ClickState state)
    {
        if (clickState == state)
        {
            return;
        }

        switch (clickState)
        {
        case ClickState.Default:
            break;

        case ClickState.PlacingTower:
            _tapPosition = Input.mousePosition;

            RaycastHit hit;
            Physics.Raycast(Camera.main.ScreenPointToRay(_tapPosition), out hit);

            if (CheckPlace(hit) && !IsPointerOnUI())
            {
                GameObject towerPrefab    = GameController.Instance.towerPrefabs[indexPlacingTower];
                GameObject newTowerObject = Instantiate(towerPrefab, placingTower.transform.position, placingTower.transform.rotation);
                towers.Add(newTowerObject.GetComponent <BasicTower>());

                BuyTower(towers[towers.Count - 1]);
            }

            Destroy(placingTower.gameObject);

            break;

        case ClickState.TowerSelect:
            selectedTower.selector.SetActive(false);
            UIController.Instance.DisableSellTower();
            selectedTower = null;
            break;
        }

        clickState = state;
        switch (state)
        {
        case ClickState.Default:
            break;

        case ClickState.PlacingTower:
            placingTower      = Instantiate(GameController.Instance.towerTemps[indexPlacingTower]);
            _placingBlankMesh = placingTower.transform.GetChild(0).GetComponent <MeshRenderer>();
            break;

        case ClickState.TowerSelect:
            selectedTower = towers[indexSelectedTower];
            selectedTower.selector.SetActive(true);
            UIController.Instance.EnableSellTower(selectedTower.GetComponent <BasicTower>());
            break;
        }
    }
Exemple #2
0
    private void OnMouseDown()
    {
        if (!hasTower && canHaveTower)
        {
            if (inv.Current_Stone_Total >= inv.Basic_Tower_Price_Int)
            {
                GameObject BasicTower;
                BasicTower             = Instantiate(Tower, new Vector3(transform.position.x, transform.position.y + 5, transform.position.z), new Quaternion(0, 0, 0, 0));
                currentTower           = BasicTower.GetComponent <TowerBehaviour>();
                currentTower.towerName = "BasicTower";
                currentTower.PosOnGrid = new Vector2(PosX, PosY);

                hasTower = true;
                inv.Current_Stone_Total -= inv.Basic_Tower_Price_Int;
            }
        }
        else if (!hasTower && TileType == Type.Water)
        {
            if (inv.Current_Stone_Total >= inv.Pump_Price_Int)
            {
                GameObject Pump;
                Pump         = Instantiate(Tower, new Vector3(transform.position.x, transform.position.y + 5, transform.position.z), new Quaternion(0, 0, 0, 0));
                currentTower = Pump.GetComponent <TowerBehaviour>();

                currentTower.towerName = "Pump";
                currentTower.PosOnGrid = new Vector2(PosX, PosY);

                hasTower = true;
                inv.Current_Stone_Total -= inv.Pump_Price_Int;
            }
        }
        else if (!hasTower && TileType == Type.Stone)
        {
            if (inv.Current_Stone_Total >= inv.Drill_Price_Int)
            {
                GameObject Drill;
                Drill        = Instantiate(Tower, new Vector3(transform.position.x, transform.position.y + 5, transform.position.z), new Quaternion(0, 0, 0, 0));
                currentTower = Drill.GetComponent <TowerBehaviour>();

                currentTower.towerName = "Drill";
                currentTower.PosOnGrid = new Vector2(PosX, PosY);
                hasTower = true;
                inv.Current_Stone_Total -= inv.Drill_Price_Int;
            }
        }
    }