using UnityEngine;
using System.Collections;

public class Magic : MonoBehaviour {

	private MeController mc;
	private GameObject player;
	private GameObject cam;
	private bool startShow = false;

	// Use this for initialization
	void Start () {
		cam = GameObject.FindGameObjectWithTag ("side");
	}
	
	// Update is called once per frame
	void Update () {
//		if (startShow) {
//
//			cam.camera.orthographic = false;
//			iTween.RotateTo(cam,iTween.Hash(
//				"x", 30,
//				"y", -45,
//				"time",2f, 
//				"easeType", "easeInOutQuad"));
//			iTween.MoveTo(cam,iTween.Hash(
//				"y", 15,
//				"z", -15,
//				"time",4f, 
//				"easeType", "easeInOutQuad"));
//
//			player.transform.Translate(-1 * Time.deltaTime * 5, 0, 0);
//		}
	}

	void OnTriggerEnter(Collider c) {
		mc = c.GetComponent<MeController> ();
		player = GameObject.FindGameObjectWithTag ("Player");
		mc.isAlive = false;
		Destroy(player.GetComponent<Rigidbody>());
		Destroy(player.GetComponent<CapsuleCollider>());
		mc.showTime = true;
		StartCoroutine (StartMagic());
	}

	private IEnumerator StartMagic() {
		cam.camera.orthographic = false;

		player.renderer.material.shader = Shader.Find("Diffuse");
		iTween.ColorTo (player, new Color(0.937f, 0.408f, 0.098f, 1), 4f);

//		iTween.ColorTo(player,iTween.Hash(
//			"r", 239,
//			"g", 104,
//			"time",4f, 
//			"easeType", "easeInOutQuad"));

		iTween.RotateTo(cam,iTween.Hash(
			"x", 30,
			"y", -45,
			"time",4f, 
			"easeType", "easeInOutQuad"));
		iTween.MoveTo(cam,iTween.Hash(
			"y", 15,
			"z", -15,
			"time",4f, 
			"easeType", "easeInOutQuad"));

		yield return new WaitForSeconds (4f);

		iTween.RotateTo(player,iTween.Hash(
			"z", 90,
			"time",4f, 
			"easeType", "easeInOutQuad"));

		yield return new WaitForSeconds (4f);

		iTween.MoveTo(player,iTween.Hash(
			"x", -8,
			"time",2.5f, 
			"easeType", "easeInOutQuad"));
		iTween.MoveTo(cam,iTween.Hash(
			"x", -120,
			"time",4f, 
			"easeType", "easeInOutQuad"));
	}
}
