How to reset orbit camera distance?

Hey,
I’m attempted to use one of the Orbit Camera scripts from the wiki. I modified the script a little to my needs I’m encountering an annoyance that I tried to fix, but I guess I’m doing it the wrong way.

Basically, I’m trying to make the script store the distance(between the camera and the player) it had before the raycast occurred in a variable, and then set the distance back to that variable.

if (Physics.Linecast(target.position, transform.position, out hit))
{
    // resetCam was given a value of 'false' at Start().
    resetCam = true;
    if (resetCam)
        oldDist = distance;
    distance -= hit.distance;
}
else
{
    if (resetCam)
    {
        distance = oldDist;
        resetCam = false;
    }
}

EDIT: If you need me to provide you with more parts of the source code, please just ask.

Please don’t give me the full code. I just need an explanation, or just a direction to follow, although SOME code would be welcome. If you could, please explain why my modification wasn’t working, and what I did wrong.

Thank you,
SeeSharp.

As robertbu commented:

I don’t know how the code is being called. If it is called (and successfully hits something) more than once before ‘oldDist’ is used, then ‘oldDist’ will be overwritten by the current distance and therefore not available on line 13 when you need it. This might work:

if (!resetCam)
    oldDist = distance;
distance -= hit.distance;
resetCam = true;