Exemple #1
0
 public override void OnEnter(params object[] paramList)
 {
     gameObject.SetActive(true);
     if (paramList != null && paramList.Length > 0)
     {
         m_BuildPlace = (BuildPlace)paramList[0];
     }
     GameManager.Instance.SelectGrid(m_BuildPlace.transform.position);
     BuildClick(m_BuildData.BuildList[0]);
 }
Exemple #2
0
    public void BuildTowerOn(BuildPlace buildPlace)
    {
        if (PlayerStats.Money < towerToBuild.cost)
        {
            Debug.Log("Too poor");
            return;
        }
        PlayerStats.Money -= towerToBuild.cost;
        GameObject tower = (GameObject)Instantiate(towerToBuild.prefab, buildPlace.GetBuildPosition(), Quaternion.identity);

        buildPlace.tower = tower;
        GameObject effect = (GameObject)Instantiate(buildEffect, buildPlace.GetBuildPosition(), Quaternion.identity);

        Destroy(effect, 3f);
    }
Exemple #3
0
    public void UpdateTower()
    {
        BuildPlace buildPlace = currentTower.buildPlace;

        Destroy(currentTower.gameObject);

        /*Transform towerInst = GameObject.Instantiate(towerPrefab, currentTower.ownTransform.position, Quaternion.identity);
         * Tower tower = towerInst.GetComponent<Tower>();
         * tower.buildPlace = buildPlace;
         *
         * TowerLevel towerData = tower.towerData;
         * int towerPrice = towerData.price;
         * tower.priceToReturn = towerPrice + price;
         *
         * levelManager.AddGold()*/
    }
    public void BuildTower()
    {
        BuildPlace buildPlace = GetComponentInParent <BuildPlace>();
        Transform  towerInst  = Instantiate(tower.transform, buildPlace.ownTransform.position, tower.transform.rotation);

        towerInst.parent = buildPlace.ownTransform.parent;
        Tower newTower = towerInst.GetComponent <Tower>();

        newTower.buildPlace = buildPlace;

        buildPlace.gameObject.SetActive(false);

        TowerLevel towerData = newTower.towerData;
        int        price     = towerData.price;

        newTower.priceToReturn = price;

        levelManager.AddGold(price * (-1));
        levelManager.SelectedObject = null;
    }
    // Update is called once per frame
    void Update()
    {
        // Set the resource Variables
        MoneyGained.text            = "$" + gameManager.moneyFix.ToString("0.00") + " +" + gameManager.MoneyGained.ToString("0.##");
        ResearchGained.text         = gameManager.Research.ToString("0.##") + " +" + gameManager.ResearchGained.ToString("0.##");
        PowerGained.text            = gameManager.CurrentPower.ToString("0.##") + " +" + gameManager.PowerGained.ToString("0.##");
        MaxPower.text               = gameManager.MaxPower.ToString("0.##");
        StoragePercent.text         = gameManager.StoragePercent.ToString("0.##") + "%";
        StorageRepresentation.value = gameManager.StoragePercent;

        // Has the user clicked the primary mouse button
        if (Input.GetMouseButtonDown(0))
        {
            // Is the current mouse location over the UI?
            if (LevelEventSystem.IsPointerOverGameObject())
            {
            }
            else
            {
                //Setup the ray based on the mosue location
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                // Perform a raycast to determine what we have hit
                RaycastHit HitResults;
                if (Physics.Raycast(ray, out HitResults))
                {
                    // Retrieve the gameobject that was hit
                    GameObject HitObject = HitResults.collider.gameObject;

                    BuildPlace buildplace = HitObject.GetComponent <BuildPlace> ();
                    if (buildplace != null)
                    {
                        buildplace.ReactToMouseClick();
                    }
                    else
                    {
                        // Attempt to find buildplace as parent
                        buildplace = HitObject.GetComponentInParent <BuildPlace> ();
                        if (buildplace != null)
                        {
                            buildplace.ReactToMouseClick();
                        }
                    }
                }
            }
        }

        // Has the user clicked the right mouse button
        if (Input.GetMouseButtonDown(1))
        {
            if (LevelEventSystem.IsPointerOverGameObject())
            {
            }
            else
            {
                //Setup the ray based on the mosue location
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                // Perform a raycast to determine what we have hit
                RaycastHit HitResults;
                if (Physics.Raycast(ray, out HitResults))
                {
                    // Retrieve the gameobject that was hit
                    GameObject HitObject = HitResults.collider.gameObject;

                    BuildPlace buildplace = HitObject.GetComponent <BuildPlace> ();
                    if (buildplace != null)
                    {
                        buildplace.ReactToMouseClick();
                    }
                    else
                    {
                        // Attempt to find buildplace as parent
                        buildplace = HitObject.GetComponentInParent <BuildPlace> ();
                        if (buildplace != null)
                        {
                            buildplace.DestroyTheObject();
                        }
                    }
                }
            }
        }
    }
Exemple #6
0
 /// <summary>
 /// Действие с местом постройки
 /// </summary>
 /// <param name="buildPlace">Место постройки</param>
 void ActionWithBuildPlace(BuildPlace buildPlace)
 {
     //levelManager.SelectedObject = null;
 }