Slowly orbit camera on keypress

I used the generic orbit camera script and tweaked it to only rotate 90 degrees when either the left or right arrow key are pressed. It works well, the only thing now is I’d like to get it to kind of swing around as opposed to instantly snapping to the position.

I’ve read most of the other questions regarding orbiting objects but I’m pretty new to unity and don’t really know how to apply them to my situation. Here’s the code:

 var target : Transform;
 var targetOffset = Vector3.zero;
 var distance = 4.0;

var lineOfSightMask : LayerMask = 0;
var closerRadius : float = 0.2;
var closerSnapLag : float = 0.2;

var xSpeed = 200.0;
var ySpeed = 80.0;

var yMinLimit = 45;
var yMaxLimit = 45;

private var currentDistance = 10.0;
private var x = 0.0;
private var y = 0.0;
private var distanceVelocity = 0.0;

function Start () {
    var angles = transform.eulerAngles;
    x = angles.y;
    y = angles.x;
	currentDistance = distance;
	
   	if (rigidbody)
		rigidbody.freezeRotation = true;
}

function LateUpdate () {
    if (target) {
        if(Input.GetKeyDown(KeyCode.LeftArrow)){
	        x += 90;
 		}
 		if(Input.GetKeyDown(KeyCode.RightArrow)){
	        x -= 90;
 		}
 		
 		y = ClampAngle(y, yMinLimit, yMaxLimit);
 		       
        var rotation = Quaternion.Euler(y, x, 0);
        var targetPos = target.position + targetOffset;
        var direction = rotation * -Vector3.forward;
		
        var targetDistance = AdjustLineOfSight(targetPos, direction);
		currentDistance = Mathf.SmoothDamp(currentDistance, targetDistance, distanceVelocity, closerSnapLag * .3);
        
        transform.rotation = rotation;
        transform.position = targetPos + direction * currentDistance;
    }
}

function AdjustLineOfSight (target : Vector3, direction : Vector3) : float
{
	var hit : RaycastHit;
	if (Physics.Raycast (target, direction, hit, distance, lineOfSightMask.value))
		return hit.distance - closerRadius;
	else
		return distance;
}

static function ClampAngle (angle : float, min : float, max : float) {
	if (angle < -360)
		angle += 360;
	if (angle > 360)
		angle -= 360;
	return Mathf.Clamp (angle, min, max);
}

@script AddComponentMenu("Third Person Camera/Mouse Orbit"

)

Add this to your camera:

var object : Transform;
private var lastRotation : Vector3;
var rotateSpeed : float;
private var swing : float;
var toRight : boolean = false;
var toLeft : boolean = false;

function Start(){
lastRotation = transform.eulerAngles;
}

function Update(){
//Always look at the object
transform.LookAt(object);

//rotate 90 degrees to right
if(Input.GetKeyDown("right") && toLeft==false){
toRight = true;}
if(toRight && toLeft==false && Mathf.RoundToInt(transform.eulerAngles.y) != Mathf.RoundToInt(lastRotation.y)-90){
swing = Mathf.Abs(Mathf.RoundToInt(lastRotation.y)-90-Mathf.RoundToInt(transform.eulerAngles.y));
transform.RotateAround(object.position, -transform.up, rotateSpeed * swing *Time.deltaTime);}
if(Mathf.RoundToInt(transform.eulerAngles.y) <= Mathf.RoundToInt(lastRotation.y)-90){
toRight = false;
lastRotation = transform.eulerAngles;}

//rotate 90 degrees to left
if(Input.GetKeyDown("left") && toRight==false){
toLeft = true;}
if(toLeft && toRight==false && transform.eulerAngles.y != lastRotation.y+90){
swing = Mathf.Abs(Mathf.RoundToInt(lastRotation.y)+90-Mathf.RoundToInt(transform.eulerAngles.y));
transform.RotateAround(object.position, transform.up, rotateSpeed * swing * Time.deltaTime);}
if(Mathf.RoundToInt(transform.eulerAngles.y) >= Mathf.RoundToInt(lastRotation.y)+90){
toLeft = false;
lastRotation = transform.eulerAngles;}
}

Good luck with the project!