﻿using UnityEngine;
using System.Collections;

public class tripStart : MonoBehaviour {

	public string nextScene;
	bool eaten = false;
	GameObject trip;
	Vector3 tripScale;
	float add = 0.01f;

	void Update() {
		if (eaten) {
			tripScale.x += add;
			tripScale.y += add;
			trip.transform.localScale = tripScale;
			add += 0.01f;
		}

		if (add > 1f) {
			Debug.Log ("Start new Level");
			NextLevel (nextScene);
		}
	}

	void OnTriggerEnter2D(Collider2D other){
		if (other.name == "Player") {
			trip = GameObject.FindGameObjectWithTag("trip");
			tripScale = trip.transform.localScale;
			eaten = true;
			//Destroy (gameObject);
		}
	}

	public void NextLevel(string scene){
		//start next level
		Application.LoadLevel(scene);
		//SceneManager.LoadScene ();
	}

	public void endTrip(){
		Application.Quit ();
	}
}
