Camera Zoom in and out

Ok so im trying to get used to coding movements and im finding it a pain in the ass. This is the first proper time im trying to do everything from scratch. The problem i am having is.

I want to zoom my camera in with the mouse scroll wheel but only scroll if you are between 2 values minDistance , maxDistance the thing is the code works but it goes below my min value even though i am doing checks. When i goes below this value it just stays there because the arguments are now false. Any help and advice would be greatly appreciated i can code nearlly anything else i can think of i have always been a bit scared of coding movements but now im hooked but can’;t get it to work lol. EDIT (I want to zoom in on my character and zoom out from him).

Here is the code

using UnityEngine;
using System.Collections;

public class CameraMovement : MonoBehaviour {

    public float rotateSpeed;
    public Transform camera = Camera.main.transform;
    public Vector3 camPosition;
    public float camSpeed;
    public Transform target;
    public float minDistance;
    public float maxDistance;
    private Vector3 moveDirection = Vector3.zero;
	// Use this for initialization
	void Start () 
    {
        camPosition = camera.transform.position;
        Debug.Log(camPosition);
	}
	
	// Update is called once per frame
    void Update()
    {
        transform.LookAt(target);
        float distanceToTarget = Vector3.Distance(target.position, transform.position);
        if (Input.GetAxisRaw("Mouse ScrollWheel") > 0)
        {
            Debug.Log(distanceToTarget);
            if (maxDistance > distanceToTarget && minDistance < distanceToTarget)
            {
                camPosition += (Vector3.forward * camSpeed * Time.smoothDeltaTime);
                camera.transform.position = camPosition;
            }
        }
        // now reset the position if the distance to target is not inbetween these values
        
    }

    
}

It’s better to make the zoom in/out effect by changing the camera’s FOV (field of view) angle - take a look at my answer in this question.

Anyway, if you want to move the camera, change some things in your script (which I suppose is attached to the camera):

    ...
    void Update()
    {
        transform.LookAt(target);
        float distanceToTarget = Vector3.Distance(target.position, transform.position);
        float scroll = Input.GetAxis("Mouse ScrollWheel");
        if (scroll != 0)
        {
            if (maxDistance > distanceToTarget && minDistance < distanceToTarget)
            {
                camPosition += transform.forward * scroll * camSpeed;
                transform.position = camPosition;
            }
        }
    }

But notice that the distance checking is being done before the movement, thus the camera will always be stopped after passing one of the limits. Notice also that this code should be attached to the camera; if you want to have it in another object and drag the camera to it, change the name of the variable camera to anything else - camera is the name of an Unity property, which will become obscured by your variable. Furthermore, the distance is being calculated from the current transform to the target, not from the camera transform.