Пример #1
0
    private void Update()
    {
        RaycastHit hit;
        Ray        ray = cachedCamera.ScreenPointToRay(Input.mousePosition);

        Debug.DrawRay(ray.origin, ray.direction * 10f, Color.red);

        if (Physics.Raycast(ray, out hit, 100f, gridLayerMask))
        {
            currentNode = hit.collider.GetComponent <GameNode>();
            if (currentNode != null && currentNode.IsEmpty)
            {
                //Node node = currentNode.GetComponent<Node>();
                //if(!node.IsVisitable)
                transform.position = currentNode.transform.position;
            }
        }
        else
        {
            currentNode = null;
        }

        if (Input.GetMouseButtonDown(0) && currentNode != null)
        {
            GameObject towerObject = Instantiate(data.prefab, transform.position, transform.rotation);
            Tower      tower       = towerObject.GetComponent <Tower>();
            currentNode.SetTower(tower);
            shopStatus.SetStatus(ShopStatus.None);
            Destroy(this.gameObject);
        }
    }
Пример #2
0
    public void TryBuyNewTower(Evolution evolution)
    {
        if (!statusValue.Status.Equals(ShopStatus.None))
        {
            return;
        }

        if (inventory.CurrentGold >= evolution.cost)
        {
            inventory.ReduceGold(evolution.cost);
            GameObject       towerObject = Instantiate(towerPlaceholderPrefab, Vector3.zero, Quaternion.identity);
            TowerPlaceholder placeholder = towerObject.GetComponent <TowerPlaceholder>();
            placeholder.Init(evolution.tower);
            statusValue.SetStatus(ShopStatus.Buying);
        }
    }