TCOP_cameraController

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour {
    public int cameraRotation = 0;
    public float distanceToTarget = 5f;
    public float cameraHeight = 6f;
    public GameObject cameraTarget;
    private float damping = 1;
    private Vector3 offset;

    void Start () {
        //setup position
        transform.position = new Vector3((cameraTarget.transform.position.x), (cameraTarget.transform.position.y + cameraHeight), (cameraTarget.transform.position.z - distanceToTarget));
        offset = transform.position - cameraTarget.transform.position;
    }

    void LateUpdate() {
        //Rotate camera around target
        if (Input.GetButtonUp ("RotateLeft")) {
            if ((cameraRotation + 1) > 3) {
                rotateCameraToPosition(0);
            } else {
                rotateCameraToPosition(cameraRotation + 1);
            }
        }

        if (Input.GetButtonUp ("RotateRight")) {
            if ((cameraRotation - 1) < 0) {
                rotateCameraToPosition(3);
            } else {
                rotateCameraToPosition(cameraRotation - 1);
            }
        }

        //Keep the distance with the target
        Vector3 desiredPosition = cameraTarget.transform.position + offset;
        Vector3 position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * damping);
        transform.position = position;

        //Look at the target
        transform.LookAt(cameraTarget.transform.position);
    }

    int cameraRotationAngle () {
        int[] cameraAngles = {0, 90, 180, 270};
        int currentAngle = (Mathf.RoundToInt (transform.eulerAngles.y / 90) * 90);

        int minusAngle = cameraAngles [cameraRotation] - currentAngle;
        int plusAngle = cameraAngles [cameraRotation] + currentAngle;

        if (Mathf.Abs(minusAngle) <= Mathf.Abs(plusAngle)) {
            return minusAngle;
        } else {
            return plusAngle;
        }
    }

    public void rotateCameraToPosition(int position){
        if(position >=0 && position <= 3 && position != cameraRotation){
            cameraRotation = position;
            offset = Quaternion.AngleAxis (cameraRotationAngle (), Vector3.up) * offset;
        }
    }
}