Esempio n. 1
0
    private void WhileBuildingForge()
    {
        buildMode = true;
        cameraControler.isCameraZoomEnabled = false;
        float   distanceToGround = cameraControler.DistanceToGround(Input.mousePosition.y);
        Vector3 mouseOnPosition  = Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3(0f, 0f, distanceToGround));

        mouseOnPosition = new Vector3(mouseOnPosition.x, 50.1f + terrain.SampleHeight(mouseOnPosition), mouseOnPosition.z);
        bool goodPosition = Mathf.Abs(mouseOnPosition.x - transform.position.x) > 20f || Mathf.Abs(mouseOnPosition.z - transform.position.z) > 20f;

        goodPosition = goodPosition && !fBuilding.GetComponent <Forge>().IsColliding();
        MeshRenderer[] fMeshRenderers = new MeshRenderer[4];
        int            h = 0;

        foreach (Transform children in fBuilding.transform)
        {
            if (children.GetComponent <MeshRenderer>())
            {
                fMeshRenderers[h] = children.GetComponent <MeshRenderer>();
                h++;
            }
        }

        if (goodPosition)
        {
            foreach (MeshRenderer mRend in fMeshRenderers)
            {
                mRend.material.color = Color.green;
            }
        }
        else
        {
            foreach (MeshRenderer mRend in fMeshRenderers)
            {
                mRend.material.color = Color.red;
            }
        }
        fBuilding.transform.position = new Vector3(Mathf.Clamp(mouseOnPosition.x, transform.position.x - 40f, transform.position.x + 40f),
                                                   mouseOnPosition.y, Mathf.Clamp(mouseOnPosition.z, transform.position.z - 40f, transform.position.z + 40f));

        fBuilding.transform.Rotate(new Vector3(0f, buildingRotationSpeed * Input.GetAxis("Mouse ScrollWheel")));

        if (Input.GetKey(KeyCode.Mouse0) && goodPosition)
        {
            foreach (MeshRenderer mRend in fMeshRenderers)
            {
                mRend.material.color = Color.white;
            }
            isForgeBuilded = false;
            cameraControler.isCameraZoomEnabled = true;
            buildMode = false;
            fBuilding.GetComponent <Buildings>().Building();
            fBuilding.GetComponentInChildren <Ground>().OnBuildingStarted();
        }
    }
Esempio n. 2
0
    private void Activation()
    {
        float   distanceToGround     = cameraControler.DistanceToGround(Input.mousePosition.y);
        Vector3 mouseClickedPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3(0f, 0f, distanceToGround));
        float   distanceToUnit       = (mouseClickedPosition - transform.position).magnitude;

        if (distanceToUnit < activationDistanceTreshold)
        {
            isActivated = true;
        }
        else
        {
            isActivated = false;
        }
    }