using UnityEngine;
using System.Collections;
using Holoville.HOTween;

public class CameraMovement : MonoBehaviour
{
		public Transform target;
		float yOffset;
		public float xOffset;
		
		float startXOffset;
		public float tweenXOffset;
		
		public static CameraMovement inst;
		
		Tweener moveTween;
		
		public void Restart ()
		{
				if (moveTween != null)
						moveTween.Kill ();
				xOffset = startXOffset;
				tweenXOffset = xOffset;
		}
		
		void Awake ()
		{
				inst = this;
		}
		
		void Start ()
		{
				yOffset = this.transform.localPosition.y;
				xOffset = this.transform.localPosition.x;
				startXOffset = xOffset;
				tweenXOffset = xOffset;
				MainCharacter.onCharacterGetHit += HandleonCharacterGetHit;
		}

		void HandleonCharacterGetHit (float amount)
		{
				xOffset += 2.5f;
				moveTween = HOTween.To (this, 0.5f, "tweenXOffset", xOffset);
				
				
				//xOffset += 2.5f;
		}
		
		void Update ()
		{
				Vector3 cameraPos = this.transform.position;
				cameraPos.x = target.position.x + tweenXOffset;
				cameraPos.y = target.position.y + yOffset;
				this.transform.position = cameraPos;
		}
		
		
}
