using UnityEngine;
using System.Collections;


public class SafeCollide : MonoBehaviour {

	//private float speed = 2.0f;
	//private bool plzMove=false;
	//private GameObject oth;

	bool hasTribeMember = false;

	void OnCollisionEnter2D(Collision2D coll) {
		coll.gameObject.GetComponent<AllCharMovement> ().safeCollided = true;
		//Debug.Log ("Safe Collided");
	}

	void OnTriggerEnter2D(Collider2D other) {
		if (other.tag.Equals ("Player")&& other.GetComponent<AllCharMovement>().isActiveAndEnabled) {

			if (gameObject.GetComponent<BoxCollider2D> ().isTrigger == true&& !hasTribeMember) {
				hasTribeMember = true;
				other.GetComponent<AllCharMovement> ().safeCollided = true;
				other.GetComponent<AllCharMovement> ().anim.SetBool ("walking",false);
				other.GetComponent<AllCharMovement> ().canMoveWithKey=false;
				other.GetComponent<Collider2D> ().attachedRigidbody.isKinematic = true;
				other.GetComponent<Collider2D> ().enabled = false;
				gameObject.GetComponent<BoxCollider2D> ().isTrigger = false;
				//Debug.Log ("Trigger False");
				GameData.numOfTribees--;
			}
			if(hasTribeMember)
				other.GetComponent<AllCharMovement> ().safeCollided = true;
				

			//other.GetComponent<AllCharMovement> ().enabled = false;
			//Invoke("killScript",0.2f);



			//oth = other.gameObject;



			//plzMove = true;

			//other.transform.position = transform.position;
			//other.GetComponent<Rigidbody2D> ().isKinematic = true;
		}
	}
	/*
	void FixedUpdate () {
		if(plzMove && oth!=null)
			oth.transform.position = Vector3.MoveTowards(oth.transform.position, transform.position, Time.deltaTime * speed*10); 
		if (oth!=null && oth.transform.position == transform.position)
			plzMove = false;
	}

	void killScript()
	{
		oth.GetComponent<AllCharMovement> ().enabled = false;
		oth.transform.rotation= Quaternion.AngleAxis(180,Vector3.forward);
	}
	*/
}
