using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class goalScript : MonoBehaviour {
	public Vector3 direction;
	private bool end;
	PlayerScript p = null;
	public string next;

	void Start () {
		end = false;
	}

	void Update () {
		if (end) {
			this.transform.Translate (direction);
			p.transform.Translate (direction);
		}
	}
	public void OnTriggerEnter2D(Collider2D other){
		
		if (other == null)
			return;
		if (other.name == "Player") {
			end = true;
			p = ((PlayerScript)(GameObject.Find(other.name).GetComponent (typeof(PlayerScript))));
			p.transform.position = transform.position;
			p.transform.rotation = transform.rotation;
			GetComponent<AudioSource> ().Play ();
			((Fade)(GameObject.Find("Fade").GetComponent (typeof(Fade)))).setSpeed(0.02F);
			((Fade)(GameObject.Find("Fade").GetComponent (typeof(Fade)))).setNext(next);
			((Fade)(GameObject.Find("Fade").GetComponent (typeof(Fade)))).setGagne (true);
			((Fade)(GameObject.Find ("Fade").GetComponent (typeof(Fade)))).fadeIn ();
			((PlayerScript)other.gameObject.GetComponent (typeof(PlayerScript))).addBonus (false);
			((PlayerScript)other.gameObject.GetComponent (typeof(PlayerScript))).debugBonus ();
			//SceneManager.LoadScene ("level3");
		}
	}
}
