/*================================================================
Product:    GGJ-2017
Developer:  Onur Tanrıkulu
Company:    Onur Tanrikulu
Date:       22/01/2017 09:09

Copyright (c) 2017 Onur Tanrikulu. All rights reserved.
================================================================*/

using UnityEngine;

public class CameraController : MonoBehaviour
{
   #region Fields
    private Transform player;
    private Vector3 target;
    private const float smooth = 5f;
    private float distance;
   #endregion
 
   #region Constructors
   // code here
   #endregion
 
   #region Properties
   // code here
   #endregion
 
   #region Methods
    private void Start()
    {
        distance = GetComponent<Camera>().orthographicSize / 2f;
        player = GameObject.FindWithTag("Player").transform;
    }

    private void Update()
    {
        if (Character.Instance.IsFacingRight)
        {
            target = new Vector3(player.transform.position.x + distance, transform.position.y, -10);
        }
        else
        {
            target = new Vector3(player.transform.position.x - distance, transform.position.y, -10);
        }
    
        transform.position = Vector3.Lerp(transform.position, target, smooth * Time.deltaTime);
    }
   #endregion
}
