Esempio n. 1
0
    public void doPrimaryButtonAction()
    {
        bool isUnit = false;

        for (int i = 0; i < units.Length - 1; i++)
        {
            if (selected != null && selected.transform.CompareTag(units[i].transform.tag))
            {
                isUnit = true;
            }
        }
        if (isUnit)
        {
            unitPanel[1].image.enabled = !unitPanel[1].image.enabled;
            unitPanel[2].image.enabled = !unitPanel[2].image.enabled;
        }
        else if (rockQty >= hutCost)
        {
            placingHut          = true;
            hutPlacement        = Instantiate(hutPrefab, transform.position, transform.rotation) as GameObject;
            hutPlacementManager = hutPlacement.GetComponent <HutManager>();
        }
    }
Esempio n. 2
0
    private void dragHut()
    {
        if (rotatingHut)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Vector3 sourcePosition = new Vector3(hutPlacement.transform.position.x, hit.point.y, hutPlacement.transform.position.z);
                if (sourcePosition - hit.point != Vector3.zero)
                {
                    hutPlacement.transform.rotation = Quaternion.LookRotation(sourcePosition - hit.point, transform.up);
                }
            }

            if (!(Input.GetMouseButton(0) || Input.GetMouseButton(1)))
            {
                clickSpamLimiter = true;
            }

            if (clickSpamLimiter && (Input.GetMouseButton(0)))
            {
                hutPlacementManager.restoreTextures();
                rockQty            -= hutCost;
                hutPlacement        = null;
                hutPlacementManager = null;
                placingHut          = false;
                rotatingHut         = false;
            }
            else if (Input.GetMouseButton(1))
            {
                GameObject.Destroy(hutPlacement);
                hutPlacement        = null;
                hutPlacementManager = null;
                placingHut          = false;
                rotatingHut         = false;
                return;
            }
        }
        else
        {
            int  biome   = tb.getBiomeAtWorldCoord(hutPlacement.transform.position);
            bool isValid = !(biome == 0 || biome == 5) && Vector3.Distance(transform.position, hutPlacement.transform.position) < 200f;
            hutPlacementManager.planningTextures(isValid);

            if (Input.GetMouseButton(0) && isValid)
            {
                rotatingHut      = true;
                clickSpamLimiter = false;
                return;
            }

            if (Input.GetMouseButton(1))
            {
                GameObject.Destroy(hutPlacement);
                hutPlacement        = null;
                hutPlacementManager = null;
                placingHut          = false;
                return;
            }

            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                int layerHit = hit.transform.gameObject.layer;
                if (layerHit == LayerMask.NameToLayer("Water"))
                {
                    hutPlacement.transform.position = hit.point;
                }
            }
        }
    }