using UnityEngine;
using System.Collections;

public class Follow : MonoBehaviour {
	//Public
	public GameObject	objectToFollow	= null;
	public bool			followX			= false;
	public bool			lerpX			= false;
	public float		lerpSpeedX		= 1.0f;
	public bool			followY			= false;
	public bool			lerpY			= false;
	public float		lerpSpeedY		= 1.0f;
	public bool			followZ			= false;
	public bool			lerpZ			= false;
	public float		lerpSpeedZ		= 1.0f;
	public Vector3		offset			= Vector3.zero;
	
	//Private
	
	void Update() {
		if (objectToFollow) {
			if (followX) {
				if (lerpX) {
					this.transform.position	= new Vector3(
						Mathf.Lerp(
						this.transform.position.x,
						objectToFollow.transform.position.x + offset.x,
						Time.deltaTime * lerpSpeedX),
						this.transform.position.y,
						this.transform.position.z
						);
				} else {
					this.transform.position	= new Vector3(objectToFollow.transform.position.x + offset.x,
					                                      this.transform.position.y,
					                                      this.transform.position.z
					                                      );
				}
			}
			if (followY) {
				if (lerpY) {
					this.transform.position	= new Vector3(
						this.transform.position.x,
						Mathf.Lerp(
						this.transform.position.y,
						objectToFollow.transform.position.y + offset.y,
						Time.deltaTime * lerpSpeedY
						),
						this.transform.position.z
						);
				} else {
					this.transform.position	= new Vector3(
						this.transform.position.x,
						objectToFollow.transform.position.y + offset.y,
						this.transform.position.z
						);
				}
			}
			if (followZ) {
				if (lerpZ) {
					this.transform.position	= new Vector3(
						this.transform.position.x,
						this.transform.position.y,
						Mathf.Lerp(
						this.transform.position.z,
						objectToFollow.transform.position.z + offset.z,
						Time.deltaTime * lerpSpeedZ
						)
						);
				} else {
					this.transform.position	= new Vector3(
						this.transform.position.x,
						this.transform.position.y,
						objectToFollow.transform.position.z + offset.z
						);
				}
			}
		}
	}
}
