How to lock panning camera movement to the Y axis?

Hi, I have an environment for mobile devices that needs to allow players to scroll up and down - with an upper and lower limit.

The only script I have found allows for free movement - panning in every direction.

Could someone please help me out with this? Thanks a lot.

To clarify - I need a new script, or my current script, to allow players to touch move the camera along the Y axis only, but an upper and lower limit.

Current code:

Vector3 touchStart;

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            touchStart = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }

       if (Input.GetMouseButton(0))
        {
            Vector3 direction = touchStart - Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Camera.main.transform.position += direction;
        }
    }

Got help elsewhere - this code does the job!

    Vector3 touchStart;
    public int upperLimit = 0;
    public int lowerLimit = 7000;

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            touchStart = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }

        if (Input.GetMouseButton(0))
        {
            Vector3 direction = touchStart - Camera.main.ScreenToWorldPoint(Input.mousePosition);
            float finalYPos = Camera.main.transform.position.y + direction.y;
            finalYPos = Mathf.Clamp(finalYPos, lowerLimit, upperLimit);
            Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, finalYPos, Camera.main.transform.position.z);
            Debug.Log(finalYPos);
        }
    }
2 Likes