using UnityEngine;
using System.Collections;

public class SimpleCamera : MonoBehaviour
{

    public Transform target;
    public float heightOffset;
    public float distance;

    public float rotationSpeed;

    private Vector3 _previousPosition;

    void Start()
    {
        Screen.lockCursor = true;
        Screen.showCursor = false;
        _previousPosition = Input.mousePosition;

        transform.parent = target;
        transform.localPosition = new Vector3(0, 0, -distance);
    }

    private void LateUpdate()
    {
        Vector3 relativePos = Input.mousePosition - _previousPosition;
        _previousPosition = Input.mousePosition;

        transform.RotateAround(target.position, Vector3.up, relativePos.x * rotationSpeed * Time.deltaTime);
        transform.RotateAround(target.position, Vector3.right, relativePos.y * rotationSpeed * Time.deltaTime);
    }
}
