using UnityEngine;
using System.Collections;

public class EnemyAi : MonoBehaviour {

	Rigidbody2D r_body;
	Animator anim;

	public GameObject food;
	public float move_force;
	public float max_speed;

	private bool facing_right;
	public bool touching_sword;
	public GameObject player;
	public GameObject sword;

	// Use this for initialization
	void Start () {
	
		r_body = GetComponent<Rigidbody2D> ();
		anim = GetComponent<Animator> ();
		player = GameObject.FindGameObjectWithTag ("player");

	}
	
	// Update is called once per frame
	void Update () {

		if (touching_sword = true) 
		{
			DestroyImmediate (food);
		}
		float player_x = player.transform.position.x;
		float my_x = transform.position.x;

		if (r_body.velocity.x < max_speed && my_x < player_x)
	 {
		Move (1);

	}
		else if(r_body.velocity.x < max_speed && my_x > player_x)
		{
			Move (-1);
		}
  }
	//move enemy left or right
	void Move(int movement)
	{
		//add force left or right
		//trigger animations
		r_body.AddForce (new Vector2 (movement * move_force,0));
 }
}
