示例#1
0
    private IEnumerator PlaceTower(Tower.TowerData tower)
    {
        bool placed = false;

        while (!placed)
        {
#if UNITY_EDITOR
            screenPos = Input.mousePosition;
            //TODO: make button or something with touchscreen that can cancel purchase
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                CancelTowerPurchase(tower);
                yield break;
            }
#endif
            canPlace = false;
            var worldPoint = cam.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, (Hub.transform.position - cam.transform.position).magnitude));
            worldPoint.y = .5f;
            newTower.transform.position = worldPoint;
            var cols = Physics.OverlapBox(new Vector3(worldPoint.x, worldPoint.y, worldPoint.z), new Vector3(towerPrefab.transform.localScale.x * 1.75f, 1, towerPrefab.transform.localScale.z * 1.75f));

            for (int i = 0; i < cols.Length; i++)
            {
                if (cols[i].gameObject == newTower)
                {
                    continue;
                }
                if (cols[i].gameObject.tag == "Tower" || cols[i].gameObject.tag == "Hub")
                {
                    canPlace = false;
                    break;
                }
                if (cols[i].gameObject.tag == "Area")
                {
                    canPlace = true;
                }
            }
            //TODO: change to button for placing.
            if (canPlace && Input.GetMouseButton(0))
            {
                placed = true;
            }

            if (canPlace)
            {
                rend.material.color = Color.green;
            }
            else
            {
                rend.material.color = Color.red;
            }
            yield return(null);
        }
        rend.material.color = Color.blue;
    }
示例#2
0
 public void CancelTowerPurchase(Tower.TowerData tower)
 {
     Destroy(newTower);
     Player.PlayerData.Money += tower.buyCost;
 }
 public void Awake()
 {
     data = levels[0];
 }