Smoothly rotation

Hi,
I would like to rotate my camera from x point to y point smoothly.

My code works well, but the camera doesn’t go back behind the target smoothly.

The issue is with the transform.eulerAngles.

void Update () {
  
        if (Input.GetMouseButton (0)) {

            transform.Rotate (new Vector3 (0, Input.GetAxis ("Mouse X") * 250, 0) * Time.deltaTime);

        }
        else if (transform.position.x != 8) {
            transform.eulerAngles = new Vector3(0, 20, 0) * Time.deltaTime;
        }
    }

Okay how and when you want it to rotate? with mouse input or what. can you describe situation more?
you want to smooth out transform rotate or euler angles

When I release the mouse button. This script works, but the camera doesn’t rotate to 0,20,0 smoothly.

I would like to smooth out the eulerAngles, because for the moment that’s more like a teleport.

IEnumerator MoveTo(Vector3 startPos, Vector3 endPos, float overTime)
    {
        float i = 0f;
        while (i <= overTime)
        {
            transform.eulerAngles = Vector3.Lerp(startPos, endPos, i/overTime);
            i += Time.deltaTime;
            yield return null;
        }
        transform.eulerAngles = endPos;
        yield return null;
    }

for this instaead of your transform.euler you need to call this function like this

MoveTo(transform.rotation, new Vector3(0,20,0), 2f);

change 2f to time you want (this means it will complete rotation in 2 seconds.

move to is new function and not part of update