Camera Zoom script stops ability to pan

Hi guys sorry if this question seems noobish. I’m trying to get a camera script working. My game is a 3d top down and I want to be able to pan around the camera while being able to zoom in and out smoothly within a range. I got the panning to work fine but when I put the zoom functions in, the panning stops working. PS. Not sure if it matters the camera is child of the player object just so it can be a reference point to the zoom range.

Blockquote
using UnityEngine;
using System.Collections;

public class CameraZoom2 : MonoBehaviour
{
	public float moveSpeed= 60.0f;
	public float distance;
	private float sensitivityDistance = 50f;
	private float damping = 2.5f;
	private float min = 10;
	private float max = 50;
	private Vector3 ydistance;
	
	void Start ()
	{
		distance = -10f;
		distance = transform.localPosition.y;
	}

	void Update ()
	{
		//Camera Movement
		var x = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
		var y = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
		transform.Translate(x, y, 0);
		//Camera Zoom
		distance -= Input.GetAxis("Mouse ScrollWheel") * sensitivityDistance;
		distance = Mathf.Clamp(distance, min, max);
		ydistance.y = Mathf.Lerp(transform.localPosition.y, distance, Time.deltaTime * damping);
		transform.localPosition = ydistance;
	}
}

Any help will be greatly appreciated! Thanks

I figured it out. I’m not sure if this is the most practical way but I decided to make the camera the child of another empty object and I assigned the movement script to that empty object.