Пример #1
0
    void Update()
    {
        // ray
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        // always casting
        if (Physics.Raycast(ray, out hit))
        {
            finalPosition = grid.GetNearestPointOnGrid(hit.point);
        }

        if (isMobile)
        {
            if (Input.touchCount > 0)
            { //if there is any touch
                touchDuration += Time.deltaTime;
                touch          = Input.GetTouch(0);

                if (touch.phase == TouchPhase.Ended && touchDuration < 0.2f) //making sure it only check the touch once && it was a short touch/tap and not a dragging.

                {
                    StartCoroutine("singleOrDouble");
                }
            }
            else
            {
                touchDuration = 0.0f;
            }
        }
        if (Application.isEditor)
        {
            // click on objects
            if (!IsPointerOverUIObject()) // if not over ui
            {
                Transform go = hit.transform;
                if (Input.GetMouseButtonDown(0))
                {
                    if (go != null)
                    {
                        HandleObjectsInteraction(go.gameObject, hit.point);
                    }
                }
            }

            if (chosenPrefabToBuild != null)
            {
                buildFrameObject.transform.position = finalPosition;
            }

            if (Input.GetKeyDown(KeyCode.F))
            {
                GenerateForest();
            }

            if (Input.GetMouseButtonDown(1)) // exit build mode or rmb #todo: rework this, dunno how
            {
                ExitBuildMode();
            }
        }
    }
Пример #2
0
    private void PlaceCubeNear(Vector3 clickPoint)
    {
        Vector3 finalPosition = grid.GetNearestPointOnGrid(clickPoint);

        transform.position = finalPosition;
    }