How to get crosshair to smoothly pan to centre of screen

Hello! I am currently making an FPS with a crosshair aim button. I can get the crosshair to “snap” back to the middle of the screen after aiming, however I would like it to track from where it was aiming back to the centre but can seem to get it to do so. Any help in acheiving this would be a big help. It is probably a simple fix, but I am a very amature programmer as I just like to work on my game in my spare time as a hobby. I have tried using an IEnumerator but it does not seem to work. Any advice would be greatly appreciated! Thank you. Here is the relevant code I am using currently -

Quaternion startAngle;
Quaternion currentAngle;
const float aimSpeed = 2.0f;

IEnumerator ReturnAim()
     {
    CameraController.instance.target.transform.localRotation = Quaternion.Lerp(currentAngle, startAngle, aimSpeed * Time.deltaTime);
     yield return null; 
     }

Hi @RoobotShepard , you are on the right track but any animation you want to make via code requires you to update its value each frame. So, in this case, you only need to put the code inside a *while* loop like this:

Quaternion targetRotation;
const float aimSpeed = 2.0f;
Transform cameraTransform = CameraController.instance.target.transform;

IEnumerator ReturnAim()
{
    Quaternion currentRotation = cameraTransform.rotation;
    while (currentRotation != targetRotation)
    {
        cameraTransform.rotation = Quaternion.RotateTowards(currentRotation, targetRotation, aimSpeed * Time.deltaTime);
        currentRotation = cameraTransform.rotation;
        yield return new WaitForEndOfFrame();
    }
    yield return null;
}

Notice that I changed the *Quaternion.Lerp* for *Quaternion.RotateTowards* just because even if they can achieve the same, RotateTowards is the correct way of doing it and you don't have to keep track of the time passed since the animation started.

The *yield return new WaitForEndOfFrame();* is just a failsafe to avoid Unity from getting hanged in the while loop.

Hope this helps.