Пример #1
0
    void SpawnTowers()
    {
        towers = new Dictionary <TowerLocation, TowerSprite>();
        foreach (KeyValuePair <TowerLocation, Vector3Int> towerPos in towerPositions)
        {
            TowerLocation towerLoc = towerPos.Key;
            Vector3Int    position = towerPos.Value;

            GameObject tower = Instantiate(towerPrefab, position, Quaternion.identity);
            tower.transform.SetParent(this.transform);
            TowerSprite towerSprite = tower.GetComponent <TowerSprite>();
            towerSprite.OnInitializedSpawnAtTilePosition(position);
            towers[towerLoc] = towerSprite;
        }
    }
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (!EventSystem.current.IsPointerOverGameObject())
            {
                BuildMenu.CloseMenu();
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out hit))
                {
                    TowerLocation towerLocation = hit.collider.gameObject.GetComponent <TowerLocation>();
                    if (towerLocation != null)
                    {
                        towerLocation.OpenMenu();
                    }
                }
            }
        }
    }
Пример #3
0
 public void SetLocation(TowerLocation towerLocation)
 {
     selectedLocation = towerLocation;
 }