using UnityEngine;
using System.Collections;

public class IA : MonoBehaviour {
	player inter ;
	public GameObject monstro;


	// Use this for initialization
	void Start () {
		inter = monstro.GetComponent<player> ();
	
	}
	
	// Update is called once per frame
	void Update () {
				transform.LookAt (player.position);
				if (player.position.x >= transform.position.x) {
						transform.Translate (0.05f, 0, 0);
				} else {
						transform.Translate (-0.05f, 0, 0);
				}
				if (player.position.z >= transform.position.z) {
						transform.Translate (0, 0, 0.05f);
				} else {
						transform.Translate (0, 0, 0.05f);
				}
				float distance_x = player.position.x - transform.position.x;
				if (distance_x < 0)
						distance_x *= -1;
				float distance_z = player.position.z - transform.position.z;
				if (distance_z < 0)
						distance_z *= -1;
				if (distance_z > 30.0f) {
						transform.position = new Vector3 (player.position.x - 5.0f, player.position.y + 1f, player.position.z);
				}
				if (distance_z > 30.0f) {
						transform.position = new Vector3 (player.position.x, player.position.y + 1f, player.position.z - 5.0f);
				}
		}
	void OnTriggerEnter(Collider other){
	if (other.collider.tag == "Player") 
	{
		player.position = new Vector3(671f, -21.6f,-331.6f);
	}
}

}
