using UnityEngine;
using System.Collections;

public class InteractiveObjectScript : MonoBehaviour {

	public GameObject dialog;

	public int id_verification;

	private GameObject myDialog;
	
	private int get_player_id;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void OnTriggerStay2D(Collider2D obj){



		if (obj.gameObject.GetComponent<PlayerScript>() != null)
		{

			get_player_id = obj.gameObject.GetComponent<PlayerScript>().id;

			if(id_verification == get_player_id || id_verification == 0)
			{
				if(Input.GetButtonDown("Fire1")){
					if (this.myDialog == null)
					{
						obj.gameObject.GetComponent<PlayerScript>().player_state = PlayerScript.PlayerState.ReadingDialog;
						this.myDialog = Instantiate(dialog) as GameObject;
					} else {
						obj.gameObject.GetComponent<PlayerScript>().player_state = PlayerScript.PlayerState.Moving;
						Destroy(this.myDialog);
				}
			}
			}
		}
	}

	void OnTriggerExit2D (Collider2D obj){
		if (obj.gameObject.GetComponent<PlayerScript>() != null)
		{
			GameObject jogador = obj.gameObject;
			jogador.GetComponent<PlayerScript>().objetoInterativo = null;
		}
	}
}
