Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        SetGridPlane();

        /*int checkX;
         * int checkY;
         * grid.GetXZ(Utility.GetMouseWorldPosition(mouseColliderLayerMask), out checkX, out checkY);*/
        //buildChecker.position = grid.GetWorldPosition(checkX, checkY);

        if (Input.GetMouseButtonDown(0))
        {
            if (!TowerPanel.activeSelf)
            {
                int checkX;
                int checkY;
                grid.GetXZ(Utility.GetMouseWorldPosition(mouseColliderLayerMask), out checkX, out checkY);

                buildChecker.position = grid.GetWorldPosition(checkX, checkY);

                grid.GetXZ(Utility.GetMouseWorldPosition(mouseColliderLayerMask), out int x, out int z);

                if (x >= 0 && z >= 0 && x < gridWidth && z < gridHeight)
                {
                    buildX = x;
                    buildZ = z;

                    selectedSpace = grid.GetGridObject(x, z);

                    if (selectedSpace.CanBuild())
                    {
                        // Show Buy Menu - currently same menu (TODO: Add separate contextual menus!)
                        TowerPanel.SetActive(true);
                        for (int i = 0; i < TowerPanel.transform.childCount; i++)
                        {
                            TowerPanel.transform.GetChild(i).GetComponent <Button>().interactable = false;
                        }

                        TowerPanel.transform.GetChild(0).GetComponent <Button>().interactable = true;
                    }
                    else if (selectedSpace.GetTransform() != null)
                    {
                        // Show Sell/Modify Menu - currently same menu (TODO: Add separate contextual menus!)
                        TowerPanel.SetActive(true);
                        for (int i = 0; i < TowerPanel.transform.childCount; i++)
                        {
                            TowerPanel.transform.GetChild(i).GetComponent <Button>().interactable = false;
                        }

                        TowerPanel.transform.GetChild(2).GetComponent <Button>().interactable = true;
                    }
                }
            }
        }

        /*if (Input.GetMouseButtonDown(0))
         * {
         *  //logic for selling tower using tags and raycasting
         *
         *  Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         *  RaycastHit hit;
         *  if (Physics.Raycast(ray, out hit, 999f, mouseColliderLayerMask)) {
         *      Debug.Log(hit.collider.gameObject.tag);
         *      Debug.Log(BuildManager.instance.GetSellTower());
         *      if (hit.collider.gameObject.tag == "Tower" && BuildManager.instance.GetSellTower()) {
         *          Destroy(hit.transform.gameObject);
         *          BuildManager.instance.SetSellTower(false);
         *          Debug.Log(BuildManager.instance.GetSellTower());
         *
         *      }
         *      else
         *      {
         *          Debug.Log("Did not sell");
         *      }
         *  }
         *
         *
         *
         *  //grid.GetXZ(Utility.GetMouseWorldPosition(mouseColliderLayerMask), out int x, out int z);
         *
         *  //if (x >= 0 && z >= 0 && x < gridWidth && z < gridHeight)
         *  //{
         *  //    GridObject gridObject = grid.GetGridObject(x, z);
         *  //    Debug.Log("Can Build: " + gridObject.CanBuild());
         *  //    Debug.Log("BuildManager status" + buildManager.GetBuildTower() != null);
         *  //    if (gridObject.CanBuild() && buildManager.GetBuildTower() != null)
         *  //    {
         *  //        GameObject towerToBuild = BuildManager.instance.GetBuildTower();
         *  //        Transform tower = Instantiate(towerToBuild.transform, grid.GetWorldPosition(x, z), Quaternion.identity);
         *  //        gridObject.SetTransform(tower);
         *  //        //Remove current selection
         *  //        BuildManager.instance.SetBuildTower(null);
         *
         *      }
         *
         *
         *
         *
         *  }
         * }*/
    }