Camera Lerp from A to B, and back

Script:

using UnityEngine;

public class AimCamera : MonoBehaviour
{
    public Camera cam;
    public Transform start;
    public Transform end;
    public float smoothSpeed;

    private float startTime;
    private float journeyLength;
    //private Vector3 resetPos;

    void Start()
    {
        startTime = Time.time;
        journeyLength = Vector3.Distance(start.position, end.position);
        

    }

    //TODO FIX THIS
    void LateUpdate()
    {
        
        if (Input.GetButton("Fire2"))
        {
            float distCovered = (Time.time - startTime) * smoothSpeed;

            //float between 0 and 1
            float fractionOfJourney = distCovered / journeyLength;

            cam.transform.position = Vector3.Lerp(start.position, end.position, fractionOfJourney);
        }

        else if (Input.GetButton("Fire2") == false)
        {
            float distCovered = (Time.time - startTime) * smoothSpeed;

            float fractionOfJourney = distCovered / journeyLength;

            cam.transform.position = Vector3.Lerp(end.position, start.position, fractionOfJourney);

        }
    }
}

I have empties as a child of the player, likewise the camera is in the same “position” in the hierarchy.
147499-ifwpxcf.png
The idea is to lerp the camera from point A (start) far away, to point B (closer to the player) when pressing Fire2. Think of fortnite’s aiming system. There are several problems:

  1. The lerp seems to happen at all times even if Fire2 is not held, from A to B. Fire2 instead acts as a “switch camera” mode without any smoothness, which is not what i want.
  2. The lerp from B back to A does not work. After camera lerp from A to B, the camera stays at B. I tried to fix this in the “else if” part, but to no avail.

Help is appreciated!

void Update()
{
float amount = smoothSpeed * Time.deltaTime;
fractionOfJourney += (Input.GetKey(“Fire2”)) ? amount : -amount;

    fractionOfJourney = Mathf.Clamp(fractionOfJourney, 0, 1);

    cam.transform.position = Vector3.Lerp(start.position, end.position, fractionOfJourney);
}

this code should work

public class CameraTransition : MonoBehaviour
{
[SerializeField] Transform camTransform;
[SerializeField] Transform head;
[SerializeField] Transform arm;

    Transform current = null;

    private void Start()
    {
        current = head;
    }

    void Update()
    {
        current = Input.GetButton("Fire2") ? arm : head;

        camTransform.position = Vector3.MoveTowards(camTransform.position, current.position, 0.1f);
        camTransform.rotation = Quaternion.RotateTowards(camTransform.rotation, current.rotation, 1f);
    }
}

Make sure to chose the right amount for rotation step and translation step to be sure your rotation and translation are both finished at the same time, I believe you can calculate it or you can play with some values.