using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class FollowCamera : MonoBehaviour
{
	public GameObject FollowTarget;
	public float OrbitDistance = 3f;
	public float OrthographicSizingFactor = 0.3f;

	private void Update()
	{
#if UNITY_EDITOR
		if (!Application.isPlaying)
		{
			CalculateMovement();
		}
#endif
	}

	private void FixedUpdate()
	{
		CalculateMovement();
	}

	private void CalculateMovement()
	{
		var targetPosition = FollowTarget.transform.position;
		var cameraPosition = targetPosition + (transform.forward * -OrbitDistance);
		transform.position = cameraPosition;

		if (Camera.main.isOrthoGraphic)
		{
			Camera.main.orthographicSize = OrthographicSizingFactor * OrbitDistance;
		}
	}
}
